int
Integer value can be any length such as integers 10, 2, 29, -20, -150 etc. Python has no restriction on the length of an integer. Its value belongs to int.
Integers can be of any length, it is only limited by the memory available.
a = 5 print("a = ",a) print(a, "is of type", type(a))
a = 5 5 is of type <class 'int'> >>>
a = 5 print(a, "is of type", type(a)) print(a, "is int number?", isinstance(a,int)) print(a, "is float number?", isinstance(a,float)) print(a, "is complex number?", isinstance(a,complex))
5 is of type <class 'int'> 5 is int number? True 5 is float number? False 5 is complex number? False >>>
float
Float is used to store floating-point numbers like 1.9, 9.902, 15.2, etc. It is accurate upto 15 decimal points.
A floating point number is accurate up to 15 decimal places. Integer and floating points are separated by decimal points. 1 is integer, 1.0 is floating point number.
a=5.8 print("a = ",a) print(a, "is of type", type(a))
a = 5.8 5.8 is of type <class 'float'> >>>
a = 5.8 print(a, "is of type", type(a)) print(a, "is int number?", isinstance(a,int)) print(a, "is float number?", isinstance(a,float)) print(a, "is complex number?", isinstance(a,complex))
5.8 is of type <class 'float'> 5.8 is int number? False 5.8 is float number? True 5.8 is complex number? False >>>
complex
A complex number contains an ordered pair, i.e., x + iy where x and y denote the real and imaginary parts, respectively. The complex numbers like 2 + 14j, 2.0 + 2.3j, etc.
Complex numbers are written in the form, x + yj, where x is the real part and y is the imaginary part.
a = 1+2j print("a = ",a) print(a, "is of type", type(a))
a = (1+2j) (1+2j) is of type <class 'complex'>
a = 1+2j print(a, "is of type", type(a)) print(a, "is int number?", isinstance(a,int)) print(a, "is float number?", isinstance(a,float)) print(a, "is complex number?", isinstance(a,complex))
(1+2j) is of type <class 'complex'> (1+2j) is int number? False (1+2j) is float number? False (1+2j) is complex number? True >>>