Typecasting or type conversion in python - float to int datatype conversion

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))


No comments:

Post a Comment

Latest Post

How to Generate Barcode and QR code For Our Products

 మీ products కి barcode / QR code generate చేయాలంటే OPTION 1: ONLINE (No Coding – Quick) Best for small shops / beginners 👉Free websites: T...