Python Numbers
Numeric data can be divided into integer and real numbers. Integers can be positive or negative. Unlike many other programming languages, python does not have any upper bound on the size of the integer. The real numbers or fractional numbers are called floating point numbers in programming languages. The floating point number contains a decimal.
There are three numeric types in Python:
- int
- float
- complex
Let us look at an example
num1 = 2 #int
num2 = 3.5 #float
num3 = 3j #complex
Int
int (integer) represents the whole numbers (i.e, positive, negative, zero) without decimal
Example
a = 10
b = 646464564564564545454121245457844545454545
c = -123
print(type(a))
print(type(b))
print(type(c))
OUTPUT
<class 'int'>
<class 'int'>
<class 'int'>
Float
A float is a positive or negative number having decimals.
a = 3.20
b = 2.0
c = -65.23
print(type(a))
print(type(b))
print(type(c))
OUTPUT
<class 'float'>
<class 'float'>
<class 'float'>
Float can be an exponential number or a fraction.
a = 2.6E34
b = -12.7e10
c = 5.6E12
print(type(a))
print(type(b))
print(type(c))
OUTPUT
<class 'float'>
<class 'float'>
<class 'float'>
complex
A complex number is written with j (a + bj).
Complex numbers are a combination of real and imaginary number
a is the real part
bj is the imaginary part
a = 1+2j
b = -2j
c = 2j
print(type(a))
print(type(b))
print(type(c))
OUTPUT
<class 'complex'>
<class 'complex'>
<class 'complex'>