Guide Python Beginner

7.10 Boolean Evaluation

Truthy and falsy values in Python — the exact set of values that evaluate as False in a boolean context — and explicit bool() conversion.

2 min read

What Is It?

Python treats every value as either “truthy” or “falsy” in a boolean context (if x:, while x:, bool(x)) — not just actual True/False values.

Truthy Values

Most values are truthy by default: non-zero numbers, non-empty strings/lists/dicts, and any object that doesn’t specifically define itself as falsy.

>>> bool(1), bool("a"), bool([1])
(True, True, True)

Falsy Values

A specific, memorizable set of values are falsy: 0, 0.0, "" (empty string), [] (empty list), {} (empty dict), set() (empty set), and None.

>>> bool(0), bool(""), bool([]), bool(None)
(False, False, False, False)

bool() Conversion

Explicitly converts any value to True or False using the truthy/falsy rules above — useful for normalizing a value before storing or comparing it as a boolean.

>>> bool(0), bool(1), bool(""), bool("a"), bool([]), bool([1]), bool(None)
(False, True, False, True, False, True, False)

Quick Interview Answer

“Every value in Python is truthy or falsy in a boolean context, not just literal True/False. The falsy set is small and memorizable: 0, 0.0, '', [], {}, set(), and None — everything else is truthy by default. This is why if my_list: is the idiomatic way to check a list is non-empty instead of if len(my_list) > 0:, and why if x: behaves differently from if x is True: for any value that isn’t literally the boolean True.”

Common Mistakes

  • Writing if len(my_list) > 0: instead of the more idiomatic if my_list: — both work, but the latter is the Pythonic convention and reads more naturally.
  • Confusing if x: (truthy check) with if x is True: (identity check against the literal True) — the second rejects any truthy value that isn’t literally True, like 1 or "yes".
  • Forgetting 0 and 0.0 are falsy when using a numeric value as a flag — a legitimate zero value can accidentally be treated as “unset.”

Add More Questions to This Guide

Know a question that should be here? Share it and help the community!

Open Google Form