FalseIntermediate Examples

Boolean literal representing false/0

Falsy values in Python

Understanding all values that evaluate to False.

python
falsy_values = [False, 0, 0.0, 0j, "", [], {}, set(), None, range(0)]
for val in falsy_values:
    print(f"{str(val):>10} -> bool: {bool(val)}")

Python has many falsy values. Understanding them helps write cleaner conditional logic.

False in arithmetic

Using False as a number in calculations.

python
print(False + 1)
print(False * 10)
print(sum([True, False, True, True]))
Expected Output
1
0
3

Since bool is a subclass of int, False acts as 0 in arithmetic operations.

Want to try these examples interactively?

Open Intermediate Playground