Python Booleans & Truthy vs Falsy Evaluation

๐Ÿ Python 3 ๐ŸŸข Lesson 9 of 12 ๐Ÿ“‚ Phase 1: Python Basics ๐Ÿ“… 2026 Edition
Understand bool data type, True and False literals, comparison operators, logical and/or/not, and how Python evaluates truthiness of objects.
1The Boolean Data Type (bool)

In Python, the bool data type represents logical truth values with exactly two singleton constants: True and False (note capital T and F).

In Python, bool is actually a subclass of int, where True == 1 and False == 0.

2Comparison & Logical Operators
  • Comparisons: == (equal), != (not equal), <, >, <=, >=.
  • Logical Operators: and (both true), or (at least one true), not (inverts boolean value).
3Truthy vs Falsy Values in Python
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ FALSY VALUES IN PYTHON โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ 1. Constants: None, False โ”‚ โ”‚ 2. Zero Numbers: 0, 0.0, 0j, Decimal(0), Fraction(0) โ”‚ โ”‚ 3. Empty Sequences: '', (), [], {}, set(), range(0) โ”‚ โ”‚ 4. Custom Objects: __bool__() returns False โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Every other value in Python evaluates to TRUTHY (True)!
๐Ÿ’ป Complete Executable Code Example
# Boolean expressions and logical operators
age = 20
has_license = True
has_insurance = False

can_drive = (age >= 18) and has_license and (not has_insurance or True)
print(f"๐Ÿš— Can legally drive? {can_drive}")

# Testing Truthiness of various Python objects
test_values = [
    True, False, 1, 0, -5, "", "Hello", [], [1, 2], {}, {"key": "val"}, None
]

print("
๐Ÿ” Truthiness Evaluation Table:")
for val in test_values:
    print(f"  {repr(val):<18} -> bool(): {bool(val)}")
โš ๏ธ Common Pitfall: Using == True instead of direct boolean evaluation

Avoid writing "if is_active == True:". The Pythonic way is simply "if is_active:" or "if not is_active:".

๐Ÿ’ป Try It Yourself โ€” Hands-on Practice Challenge

Use truthiness to validate input collections and default configurations.

def process_user_cart(items):
    # Empty list [] evaluates to Falsy
    if not items:
        return "๐Ÿ›’ Your shopping cart is empty! Please add items."
    return f"โœ… Processing {len(items)} items: {', '.join(items)}"

print(process_user_cart([]))
print(process_user_cart(["MacBook Pro", "AirPods", "USB-C Hub"]))
Run This Code in Our Online Compiler โ†’
โ“ Frequently Asked Questions (FAQ)

Q: Can you perform arithmetic with booleans in Python?

Yes! Because bool is a subclass of int, True + True equals 2, and sum([True, False, True]) equals 2.

OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy & tested on Python 3.12+ runtime ยท Last updated August 2026