Python Numbers

In Python, numbers are of the following data types:

  • int
  • float
  • complex
int

int is a positive or a negative integer of any length. int should not be a decimal or a fraction.

Example:

a = -23698
b = 0
c = 10548

print(type(a))
print(type(b))
print(type(c))
<class 'int'>
<class 'int'>
<class 'int'>
Float

A float is a positive or a negative decimal number. It can be an exponential number or a fraction.

Example:

f1 = -9.35245     #decimal number
f2 = 0.000001     #decimal number
f3 = 2.6E44       #exponential number
f4 = -6.022e23    #exponential number

print(type(f1))
print(type(f2))
print(type(f3))
print(type(f4))
<class 'float'>
<class 'float'>
<class 'float'>
<class 'float'>
complex

Complex numbers are a combination of real and imaginary number. They are of the form a + bj, where a is the real part and bj is the imaginary part.

Example:

cmplx1 = 2 + 4j
cmplx2 = -(3 + 7j)
cmplx3 = -4.1j
cmplx4 = 6j

print(type(cmplx1))
print(type(cmplx2))
print(type(cmplx3))
print(type(cmplx4))
<class 'complex'>
<class 'complex'>
<class 'complex'>
<class 'complex'>