0% found this document useful (0 votes)
0 views

python 5

The document explains type conversion in programming, detailing how to convert numeric data types using specific functions such as float(), int(), and complex(). It provides examples of converting integers and floats to other types, including the output of each conversion. It also notes that complex numbers cannot be converted to integer or float types.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

python 5

The document explains type conversion in programming, detailing how to convert numeric data types using specific functions such as float(), int(), and complex(). It provides examples of converting integers and floats to other types, including the output of each conversion. It also notes that complex numbers cannot be converted to integer or float types.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

</> CodeWithHarry Menu Login

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.

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 int() function. int() function rounds of 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.

< < Previous Next > >

CodeWithHarry Copyright © 2024 CodeWithHarry.com

You might also like