Facebook PixelData Conversion | Python Tutorial | CodeWithHarry

Data Conversion

  • The process of converting numeric data from one type to another is called type conversion.
  • To convert from integer to float, we use the float() function.

To convert from integer to complex, we use the complex() function.

Example:

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 the int() function. The int() function rounds off the given number to the nearest integer value.

To convert from float to complex, we use the complex() function.

Example:

num1 = 8.4
num2 = int(num1)
num3 = complex(num1)
 
print(num2)
print(num3)

Output:

8
(8.4+0j)

Note: Complex numbers cannot be converted to integer or float.