Python Type Conversion and Type Casting
We can convert one type of variable to another type. This conversion is called type casting or type conversion.
int(): convert any type variable to the integer type.
float(): convert any type variable to the float type.
complex(): convert any type variable to the complex type.
bool(): convert any type variable to the bool type.
str(): convert any type variable to the string type.
#Type Casting float value to an integer
float(): convert any type variable to the float type.
Ex
pi = 3.14
print(type(pi))
num = int(pi)
print("Integer number:", num)
print(type(num))
Comments
Post a Comment