Python Numbers (int, float, and complex type)

Numeric types in Python are used to store numeric values. The three numeric types in Python are:

  1. int
  2. float
  3. complex

Note: The type() function is used to find the type of a value or variable. For example:

x = 45
y = 34.54
z = 12j

print(type(x))
print(type(y))
print(type(z))

The output is:

<class 'int'>
<class 'float'>
<class 'complex'>

Python int type

Any whole number is considered of the "int" type. For example, 12, 1, 0, -1345431234, 23456765432134565432, etc.

Advantages of the "int" type in Python

Disadvantages of the "int" type in Python

Python float type

Any number with a decimal (except the complex number) is classified as float.For example, 1.9, 2.0, -4253464.2433, etc.

Note: Numbers like 781E4, 23E3, -3542.6E10, etc. are also considered floating-point numbers, where e or E indicates the power of 10. Therefore, these numbers are of the "float" type.

The number 781E4 is equal to 7810000.0. Similarly, the number -3542.6e5 is equal to -354260000.0.

Note: A number in the form of 123E32 can also be called a scientific number.

Advantages of the "float" type in Python

Disadvantages of the "float" type in Python

Python complex type

Any number with an imaginary part is considered complex. For example, 23+6J, 10J, -32J, etc.

Advantages of the "complex" type in Python

Disadvantages of the "complex" type in Python

Python Online Test


« Previous Tutorial Next Tutorial »