Numeric data types of Python

Numeric data types of Python
 
In Python, there are three different numeric data types [integers, float and complex numbers]. But boolean also a sub-type of integers. Because, mathematically the value True is 1 and the value False is 0...
 

int:

  • Integers have unlimited precision...
         (e.g: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11...)
  • There is no limitations in its size...
  • It can be positive or negative...
  • Immutable (It Can't modify once created)...
 

float:

  • Float numbers are usually implemented using double in C...
  • It has decimal point and fractional values (optional)...
  • No limitations in size...
  • Float can also be scientific numbers with an "e" to indicate the power of 10...
         (e.g: 1.2, 3.0, 754.344456, -2.e3, 7648.8937597...)
  • float data type also immutable...

complex:

  • Complex numbers are written in the form x + yj, where x is the real part and y is the imaginary part...
  • You cannot convert complex numbers into another number type...
         (e.g: x = 1+0j)
  • complex data type also immutable...

bool:

  • In programming you often need to know if an expression is True or False...
  • You can evaluate any expression in Python, and get one of two answers, True or False...
  • When you compare two values, the expression is evaluated and Python returns the Boolean answer...
  • The value of True is one...
  • The value of False is zero...
    • (e.g):
                print(10 > 9)           =>  True
                print(10 == 9)         =>  False
                print(10 < 9)           =>  False

Previous Post Next Post