Python Numeric Datatypes

There are three Python Numeric Datatypes int, float, complex, and in mathematics, these are represented as integers, decimals, and complex numbers.

Example

x = 12
y = 12.3
z = 12j  # we use "j" to represant complex numbers
print(type(x))
print(type(y))
print(type(z))

Output

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

Int

In Python int, or integer is a whole number(positive, negative, and zero) and the length is unlimited.

Example

x = 1227348742474
y = -12234353546
z = 0
print(type(x))
print(type(y))
print(type(z))

Output

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

Float

In Python “Float or “floating-point numbers” are similar to decimal numbers in maths.

Example

x = 122734.8742474
y = -12234.353546
z = 0.2032
print(type(x))
print(type(y))
print(type(z))

Output

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

Complex

In Python, “complex numbersare created using “j” after a number.

Example

x = 12 + 3j
y = -12 - 0.4j
z = 4j
print(type(x))
print(type(y))
print(type(z))

Output

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

Also Read: