After reading the Python Numbers topic, you will understand numbers and its classification as float, integer, and complex in Python.
In python, numbers are classified as
- int
- float
- complex
int (Integer)
It is any number having a group of digits either from 0 to 9.
Example:
Program (1): To demonstrate how to display the integer number in Python.
x=120 print(x) print(type(x))
Output (1)
120 <class 'int'>
Explanation: for Program(1) and Output(1)
- x is variable.
- 120 is the integer value assign to variable x.
- type(x) function used inside print statement (i.e. print(type(x))) to prove that 120 is integer value.
float
It is any number containing a fractional part.
Example:
Program (1): To demonstrate how to display float number in Python.
x=120.25 print(x) print(type(x))
Output (1)
120.25 <class 'float'>
Explanation: for Program(1) and Output(1)
- x is variable.
- 120.25 is the float value assign to variable x.
- type(x) function used inside print statement (i.e. print(type(x))) to prove that 120.25 is the float value.
complex
It is any number containing having an imaginary part. The imaginary part is representing by letter j in python.
Example:
Program (1): To demonstrate how to display complex number in Python.
x=120+2j print(x) print(type(x))
output
(120+2j) <class 'complex'>
Explanation: for Program(1) and Output(1)
- x is variable.
- 120+2j is the complex value assign to variable x.
- type(x) function used inside print statement (i.e. print(type(x))) to prove that 120+2j is the complex value.