Introduction to Python Number
Python number one of the type from Python data type. Python number are used to store numeric values like 1,2,1.2 etc. In this post we will study about Python number, example and various types of number in python. In Python following type of numeric types can be used.
Types of Python number
Python integer number
In Python we can use integer numbers. Integer number like 1, 2 3 etc. are python int numbers.
Python integer number example
age=12 # it will show value of age variable print(age) #it will show the type of age variable print(type(age))
12 <class 'int'>
Explanation: Here age is Python variable to store the numeric value.
Python int can have negative values as well. See below example
credit=-5000 # it will show value of credit variable print(credit) #it will show the type of credit variable print(type(credit))
-5000 <class 'int'>
Now one question came, what is the maximum possible value of an integer in Python?
In Python 3, there is no limit of python integer, it could be as long. You can try it yourself.
Python float number
Python can deal with decimal number also like 1.5, 2.9 etc. As like python integer, Python float can deal with both negative and positive values.
Python float number example
price=25.50 debt=-90.77 # it will show value of price print(price) print(debt) #it will show the type of price print("type of price is",type(price)) print("type of debt is",type(debt))
25.5 -90.77 type of price is <class 'float'> type of debt is <class 'float'>
Python complex number
Python can have complex numbers also, e.g. 1+2j. a complex numbers are a combination of real and imaginary numbers. In Python, j is considered an imaginary number.
Example of Python complex number
x=1+2j y=-2j-1 # it will show value of x,y print(x) print(y) #it will show the type of x,y print("type of price is",type(x)) print("type of debt is",type(y))
(1+2j) (-1-2j) type of price is <class 'complex'> type of debt is <class 'complex'>
So we study about Python number and their types with example.