Python – Numbers:
In Python, Numbers can be defined in three ways.
- Integer
- Float
- Complex
Let us understand how to work with Integer numbers
1 2 3 4 5 |
>>>x = 10 # assigning the integer value to variable x >>>x 10 |
we can identify which type of value the variable x is holding
1 2 3 4 5 |
>>>x=10 >>>type(x) <class 'int'> |
Let us understand how to work with Float numbers
1 2 3 4 5 |
>>>y=10.1 # assigning the float value to variable y >>>y 10.1 |
Let us identify the type of value the variable y is holding
1 2 3 4 5 |
>>>y=10.1 >>>type(y) <class 'float'> |
Let us understand how to work with complex type
1 |
>>>x=4+2y # 4 is the real part and 2y is the imaginary part |
We can perform the various calculations with these numbers.
Let us see few examples below.
1 2 3 4 5 6 7 8 9 10 11 |
>>>5+5 10 >>>5*5 25 >>>5-4 1 |