Tuesday, June 12, 2018

Numbers in Python

What is Numbers

Numbers data types which store numeric value like integer, float, complex number

There are three numerical data type in number

Integer Number int Signed integers Ex: 10 , -700,
Float Number float Floating point real values Ex: 0.01, -21.88, 34.7+e19
Complex Number complex Complex number Ex: 4.82j, 45.j etc

Python Provide type() function to know which class or variable or value belongs.

To check an object belongs to a particular class use isinstance()

Example Of Integer:

a = 20

print(a, “ data type is”, type(a))

Output:  20 data type is <class 'int'>

Example Of Float: 

a = 20.45

print(a, “ data type is”, type(a))

Output:  20.45 data type is <class 'float'>

Example Of Complex:

a = 1+3j

print(a, “ Complex number is”, isinstance(1+3j, complex))

Output:  (1+3j) Complex number is True

Prev: Datatype in Python
Next: Strings in Python

No comments:

Post a Comment

Google+ Followers