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 Are Currently Working On Our Android Application Development and We already have two YouTube channels their name is CodeX or NightHawk. CodeX is for programming related videos and NightHawk is for online game streaming so please supporting us and Subscribe to our channels, Thank you