Showing posts with label bool to int conversion. Show all posts
Showing posts with label bool to int conversion. Show all posts

Python DataType Conversion Boolean value to an integer - Python integer to float datatype conversion

 

Python Datatype Conversion

 

#Python DataType Conversion Boolean value to an integer

flagtrue = True

flagfalse = False

print(type(flagtrue))

num1 = int(flagtrue)

num2 = int(flagfalse)

print("Integer number 1:", num1)

print(type(num1)) 

print("Integer number 2:", num2)

print(type(num2))


Output:

<class 'bool'>

Integer number 1: 1

<class 'int'>

Integer number 2: 0

<class 'int'>


#Python  integer to float datatype conversion

num = 725

print(type(num))

num1 = float(num)

print("Float number:", num1)

print(type(num1))

Output:

<class 'int'>

Float number: 725.0

<class 'float'>

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


Latest Post

Don’t Sweat It – Chill with Crompton Air Cooler Deals

 ðŸŒž Don’t Sweat It – Chill with Crompton Air Cooler Deals  More Details : https://www.amazon.in/s?k=laptops+under+70000&crid=29QIFPXQYB3...