What are the boolean values of True and False equivalent to when converted to integers?

0129

In Python, when converted to integers:

  • True is equivalent to 1.
  • False is equivalent to 0.

You can see this conversion in action with the following code:

true_int = int(True)   # 1
false_int = int(False)  # 0

print(true_int)  # Outputs: 1
print(false_int) # Outputs: 0

This means that True can be treated as 1 in arithmetic operations, and False can be treated as 0. If you have any more questions, feel free to ask!

0 Comments

no data
Be the first to share your comment!