Python Numbers
There are three numeric types in Python:
- int
- float
- complex
Variables of numeric types are created when you assign a value to them:
Example
a = 1 # intb = 2.8 # floatc = 1j # complex
To verify the type of an object in Python, use the
type()
function:Example:
print(type(a))
print(type(b))
print(type(c))
Int
Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
Example
Integers:
a = 6
b = 35677770
c = -266272
print(type(a))
print(type(b))
print(type(c))
Float
Float, or "floating point number" is a number, positive or negative, containing one or more decimals.
Example:
Floats: It's just an example.
a = 9.5
b = 7.0
c = -20.12
print(type(a))
print(type(b))
print(type(c))
Float can also be scientific numbers with an "e" to indicate the power of 10.
Example
Floats:
a = 78e90
b = 1E562
c = -88.733e0
print(type(x))
print(type(y))
print(type(z))