Python Number


Python Numbers:

There are three numeric types in Python:
  • int
  • float
  • complex

1. Int

Int(integer) can be a whole number, positive or negative but without decimals of unlimited length.

Example:

x = 0
y = 3587790048343
z = -32

print(type(x)) # type keyword is use to know the type of datatype.
print(type(y))
print(type(z))

Result:

<class 'int'>
<class 'int'>
<class 'int'>


2Float

Float("floating point number") is a number it can be positive or negative containing one or more decimals.

Example:

x = 1.100
y = 1.0
z = -98.09

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

Result:

<class 'float'>
<class 'float'>
<class 'float'>

Note: Float can also be scientific numbers with an "e" to indicate the power of 10.

Example:

x = 35e3
z = -87.7e100

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

Result:

<class 'float'>
<class 'float'>


3.Complex

Complex numbers are written with a real number as a real part and a "j" as the imaginary part:

Example:

x = 3+5j
y = 5j

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

Result:

<class 'complex'>
<class 'complex'>

Post a Comment

0 Comments