Python_Numbers


Python _Numbers

 Generally there are three numeric types in Python.
     1.   int
     2.   float
     3.   complex

Example 1:
x = 10
y = 5.5
z = 5j
print(type(x))
print(type(y))
print(type(z))

Output:
<class 'int'>
<class 'float'>
<class 'complex'>

To verify which type of object, type() function

Int type
Integer represents the whole numbers, positive or negative numbers, but it cannot show  decimal numbers.

x = 55
y = 3525646465
z = -3
print(type(x))
print(type(y))
print(type(z))

Output:

<class 'int'>
<class 'int'>
<class 'int'>
The type of object is ‘int’ type.

Float type
It represents the positive or negative numbers, that contains  decimal values.
x = 5.10
y = 10.0
z = -45.60
print(type(x))
print(type(y))
print(type(z))

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

The type of object is ‘float’ type.

Complex type
Generally complex number format is x+yj.

x = 8+5j
y = 55j
z = -10j
print(type(x))
print(type(y))
print(type(z))

Output:
<class 'complex'>
<class 'complex'>
<class 'complex'>

The type of object is ‘complex’ type.



Comments

Popular posts from this blog

Basic Operators in Python

Python Conditions