Numbers are one of the fundamental data types in Python used to represent numeric values. Python supports three main numeric types:
-
Integer (
int) — whole numbers -
Floating-point (
float) — numbers with decimals -
Complex (
complex) — numbers with real and imaginary parts
These numeric values are objects of their respective classes and allow mathematical operations like addition, subtraction, multiplication, and division.
1. Integer (int)
Integers represent whole numbers (positive, negative, or zero) without a decimal part. Python integers have unlimited precision — they can be very large without overflow.
2. Floating-Point (float)
Floats represent real numbers with a decimal point. They can also use scientific notation (e or E) to represent very large or very small numbers.
3. Complex Numbers (complex)
Complex numbers have a real and imaginary part, with the imaginary part denoted by a j or J. They are often used in advanced mathematical and engineering tasks.
Using type() to Check Number Types
To verify the type of a numeric value or variable in Python, use the built-in type() function.
Basic Arithmetic with Numbers
Python supports standard arithmetic operators:
/always returns a float.-
Integer division uses
//(floor division). -
%gives the remainder. -
**is the exponent operators