python 5
python 5
This site uses Google AdSense ad intent links. AdSense automatically generates these links and they may help creators earn
money.
Data Conversion
The process of converting numeric data from one type to another is called as
type conversion.
To convert from integer to float, we use float() function.
num1 = -25
num2 = float(num1)
num3 = complex(num1)
print(num2)
print(num3)
Output:
-25.0
(-25+0j)
To convert from float to integer, we use int() function. int() function rounds of the
given number to the nearest integer value.
num1 = 8.4
num2 = int(num1)
num3 = complex(num1)
print(num2)
print(num3)
Output:
8
(8.4+0j)