truthy
In Python, a value is truthy when it counts as true in a Boolean context, such as the condition of an if statement or a while loop. You never have to compare the value to anything. You can write if items: to ask whether a list has contents, and Python lets the object answer for itself.
Every object is truthy by default. A value is falsy only when its class defines a __bool__() special method that returns False or a __len__() method that returns zero. That keeps the built-in falsy set short enough to memorize: None, False, zero of any numeric type, and empty sequences and collections such as "", (), [], {}, and set().
Any built-in value outside that set is truthy, including values that look like they should be false, such as -1, "0", and [0]. Truthiness is also separate from being a Boolean. The bool() built-in converts a value to True or False, but and and or hand back one of their operands instead, so "" or "guest" evaluates to "guest".
Example
Say you’re building a shopping cart and you want a checkout function to bail out when the cart holds nothing:
>>> class Cart:
... def __init__(self, items):
... self.items = items
... def __len__(self):
... return len(self.items)
...
>>> def check_out(cart):
... if cart:
... return f"Checking out {len(cart)} item(s)"
... return "Your cart is empty"
...
>>> check_out(Cart([]))
'Your cart is empty'
>>> check_out(Cart(["keyboard", "mouse"]))
'Checking out 2 item(s)'
Both carts are instances of the same class, so nothing about their type decides the outcome. if cart: calls __len__() and treats the cart as truthy only when that count is nonzero. Drop the __len__() method and both carts become truthy, because an object with no opinion about its own truth value is true.
You can trace that decision for any value. Pick one below and watch which of the three questions Python answers before it commits to True or False:
Related Resources
Tutorial
Python Booleans: Use Truth Values in Your Code
In this tutorial, you'll learn about the built-in Python Boolean data type, which is used to represent the truth value of an expression. You'll see how to use Booleans to compare values, check for identity and membership, and control the flow of your programs with conditionals.
For additional information on related topics, take a look at the following resources:
- Python's all(): Check Your Iterables for Truthiness (Tutorial)
- Conditional Statements in Python (Tutorial)
- Python Booleans: Leveraging the Values of Truth (Course)
- Conditional Statements in Python (if/elif/else) (Course)
- Python any(): Powered Up Boolean Function (Course)
- Python Conditional Statements (Quiz)
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Martin Breuss • Updated Oct. 2, 2026