Python’s Truthy and Falsy Values
In Python, every value can be evaluated as True or False in a boolean context (like if statements, while loops, logical expressions).
🔹 Falsy Values
The following are considered False when evaluated in a boolean context:
NoneFalse- Numeric zeros:
0,0.0,0j(complex zero) - Empty sequences/containers:
- Empty string →
"" - Empty list →
[] - Empty tuple →
() - Empty dictionary →
{} - Empty set →
set() - Empty range →
range(0)
- Empty string →
🔹 Truthy Values
- All other values not listed above are considered True.
- Example: Non-empty strings, non-empty lists, non-zero numbers, objects, etc.
🔹 Example
if []:
print("This won't print")
else:
print("Falsy value") # [] is falsy
if [1, 2, 3]:
print("Truthy value") # Non-empty list is truthy
🔹 Output
Falsy value
Truthy value
✅ Summary:
- Falsy values:
None, False, 0, 0.0, 0j, '' , [] , () , {} , set() - Truthy values: Everything else.
