Python Numbers :

Python Numbers :

Number data types store numeric values. They are immutable data types, means that changing the value of a number data type results in a newly allocated object. There are three numeric types in Python :

  1. int
  2. float
  3. complex

Example :

  1. x = 1
  2. y = 4.8
  3. z = 1j
  4. print("python number types :\n")
  5. print(type(x))
  6. print(type(y))
  7. print(type(z))
  8. input()

Output :

python number types

Note : To verify the type of any object in Python, use the type() function.


int :

int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.

Example :

  1. x = 1
  2. y = 11796348708246
  3. z = -77885522
  4. print(type(x))
  5. print(type(y))
  6. print(type(z))
  7. input()

Output :

python int numbers

float :

float, or "floating point number" is a number, positive or negative, containing one or more decimals.

Example :

  1. x = 2.0
  2. y = 10.50
  3. z = -50.80
  4. print(type(x))
  5. print(type(y))
  6. print(type(z))
  7. input()

Output :

python float numbers

complex :

Complex numbers are written with a " j " as the imaginary part.

Example :

  1. x = 4+10j
  2. y = 7j
  3. z = -15j
  4. print(type(x))
  5. print(type(y))
  6. print(type(z))
  7. input()

Output :

python complex numbers

Next Update

Loading...

We create a new YouTube channel (NightHawk) for gaming purpose like online games streaming or games review.

We need some time for make video tutorials (CodeX) so, stay with us and keep supporting and you know already we make a Collaboration with HackIsOn YouTube channel long time ago So, please Subscribe Our Channels

Protection died IPs active, this IP range is not allowed !