bool has exactly two instances, True and False, and every object in Python has an associated truthiness that bool() can compute: values like 0, 0.0, None, and empty containers are falsy, while most everything else is truthy. Because bool is a subclass of int, True and False behave as 1 and 0 in arithmetic contexts — adding True to True really does evaluate to 2.
1Understanding Booleans
bool has exactly two instances, True and False, and every object in Python has an associated truthiness that bool() can compute: values like 0, 0.0, None, and empty containers are falsy, while most everything else is truthy. Because bool is a subclass of int, True and False behave as 1 and 0 in arithmetic contexts — adding True to True really does evaluate to 2.
Write `if value:` instead of `if value == True:` — the explicit comparison is redundant, slightly slower, and considered unidiomatic Python.
print(bool(0), bool(1), bool(""), bool("hi"))
print(True + True)2Practical Example
Here is a real-world application of Booleans showing how it is used in production Python code.
scores = [55, 90, 45, 80]
passing_count = sum(score >= 60 for score in scores)
print(passing_count)3Best Practices
Follow these guidelines when working with Booleans:
1. Rely on an object's natural truthiness (if items:) instead of comparing explicitly to True or an empty container
2. Remember bool is a subclass of int, so a boolean also counts as an instance of int — guard against that if it matters for your checks
3. Use sum() over a generator of boolean conditions to count how many items satisfy a condition, since True adds as 1
Tip: Write `if value:` instead of `if value == True:` — the explicit comparison is redundant, slightly slower, and considered unidiomatic Python.
print(bool(0), bool(1), bool(""), bool("hi"))
print(True + True)