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

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