5.04
Completed
Truthy and Falsy Values Truthy and Falsy Values

Learn how Python treats strings, numbers, and booleans as truthy or falsy, and when to use bool() versus exact comparisons.

Truthy and Falsy Values

Sounds useful?

Jump into the interactive version.

No setup. No account. Just Python.

Interactive Python lesson

Truthy and Falsy Values in Python

Python does not only work with True and False. It can also treat regular values like strings and numbers as boolean-like values when needed. This Block explains what it means for a value to be truthy or falsy, using simple examples with bool(), strings, numbers, and real boolean values.

You will see why an empty string is falsy, why 0 is falsy, why "False" is still truthy, and why quotation marks matter more than they look like they should. Tiny detail, big consequences.

What you will learn:

  • Use bool() to inspect how Python treats a value
  • Understand truthy and falsy values in plain language
  • Recognize why empty strings are falsy and non-empty strings are truthy
  • Recognize why 0 and 0.0 are falsy, while non-zero numbers are truthy
  • Tell the difference between truthiness and exact comparisons like name == ""
  • Use not with truthy and falsy values without making your code mysterious

By the end, you will understand one of those Python ideas that shows up everywhere later: simple, useful, and just sneaky enough to deserve its own Block.

> Start now 77 cards · about 5 min

Ready to practice this in the browser?

> Play now