Type casting in python
It is used to convert the data types like int,float,string.It can also performs the arithmetic operators to different data types.
1. int()
We have converted the float value 1.0 to the interger value one.
Example
n = int(1.0) print(n)
Output
1
2. float()
We have converted the integer value 1 to the float value 1.0.
Example
n = float(1) print(n)
Output
1.0
3. str()
We have converted the integer value 1 to the string value "1". Next we have converted the float value 2.0 to the string value "2.0".
Example
n = str(1) m = str(2.0) print(n) print(m)
Output
1 2.0