Skip to main content

Python Booleans

Satellite · Data Types

Python Booleans

Booleans drive control flow. Learn when values evaluate to True/False and how to avoid subtle bugs.

Truthiness

Falsy values:

  • False
  • None
  • 0, 0.0
  • Empty sequences: "", [], (), {}, set()

Everything else is truthy.

Logical operators

OperatorBehavior
andReturns first falsy operand, else last operand
orReturns first truthy operand
notNegates truthiness

Example:

user = cached_user or fetch_user()
if not user.active:
disable(user)

Next up in your learning path