Numbers

There are 3 types :

  1. Integer

  2. Float

  3. Complex

    1. Integer(int) : Integer is a non decimal number formed by the combination of 0 - 9 digts.

    2. Float(float) : Float is an decimal number that can be represented on number line.

    3. Complex(complex) : They are the numbers consist of an imaginary number and real number.

    We can use the type() function to know which class(int,float,complex) a variable or a value belongs to!!

Example - 1:

x = input("Enter any number :  ") 
#input() function is used to have input on console.
y = input("Enter any number : ")
z = input("Enter any number : ")
print(type(x)) 
#type(object) function returns the type of object.
print(type(y)) 
#print() is a function that outputs to your console window.
print(type(z))

Enter any number : 3

Enter any number : 4.5

Enter any number : 3+6j

<class 'str'>

<class 'str'>

<class 'str'>

Initially every value is a string in python so to convert them in int, float, complex we use specific functions for each conversion.

  1. For integer we use int()

  2. For float we use float()

  3. For complex we use complex()

Example - 2:

Enter a number : 3

Enter a number : 4

Type of X : <class 'int'>

Type of Y : <class 'int'>

Value of X : 3

Value of Y : 4

Id of X : 1487936480

Id of Y : 1487936496

x = 6 y = 4

Id of X : 1487936528

Id of Y : 1487936496

Example - 3:

X : 6.789654321

Y : 876543.098765432

X = 6.789654321

Type(x) = <class 'float'>

Y = 876543.098765432

Type(y) = <class 'float'>

Example - 4:

Type of X : <class 'complex'>

Value of X : (3+5j)

Example - 5:

Last updated

Was this helpful?