Python Numbers
Numbers are used to store the numeric type of data in them. Numbers are the immutable data types i.e. if we change the value of variable then it results in a new type of data.
There are three numeric types in Python:
In python, variables of any type of data type are created when you assign values to them. Variables of numeric types are created when you assign a numeric value to them: >>>x,y,z=2,2.5,1j >>>print(type(x),type(y),type(z))
If we want to verify the type of any variable or object in python then we need to use the type() fuction. The type function will give us the data type of the variable or object which is passed as the parameter in the type() function.
>>>a,b=2,-2 >>>print(type(a),type(b))
Int
An int or integer is a type of combination of the positive and negative whole numbers. An integer is written without decimals.
>>>a,b=2.25,-2.16 >>>print(type(a),type(b))
Float
A float or floating point number is a combination of the positive or negative numbers with one or more decimal points.
>>>a,b=1j,2+j5 >>>print(type(x),type(y))
Complex
A complex number is a number which is combination of the real and imaginary part and the real and imaginary parts are distinguihed from each other with 'j' and they are written in the form of 'a+jb' where 'a' represent the real part and b represent the imaginary part.