Numbers
There are 3 types :
Integer
Float
Complex
Integer(int) : Integer is a non decimal number formed by the combination of 0 - 9 digts.
Float(float) : Float is an decimal number that can be represented on number line.
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:
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.
For integer we use int()
For float we use float()
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