all()
all(iterable) Returns:
bool · Updated March 13, 2026 · Built-in Functions built-in iteration boolean validation
The all() function returns True if all elements in an iterable are truthy. It short-circuits on the first falsy value, making it efficient for checking conditions across collections.
Syntax
all(iterable)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
iterable | iterable | — | Any iterable (list, tuple, set, dict, generator, etc.) |
Examples
Basic usage
# All elements are truthy
numbers = [1, 2, 3, 4, 5]
print(all(numbers))
# True
# Contains a falsy value (0)
mixed = [1, 2, 0, 4, 5]
print(all(mixed))
# False
# Empty iterable returns True
empty = []
print(all(empty))
# True
With strings
# All non-empty strings are truthy
words = ["hello", "world", "python"]
print(all(words))
# True
# Empty string is falsy
words_with_empty = ["hello", "", "world"]
print(all(words_with_empty))
# False
# Empty string itself - vacuous truth (no characters to check)
print(all(""))
# True
With dictionaries
# All keys are truthy (non-empty strings)
d = {"a": 1, "b": 2, "c": 3}
print(all(d))
# True
# Empty key is falsy
d_with_empty = {"a": 1, "": 2, "c": 3}
print(all(d_with_empty))
# False
Common Patterns
Validating user input
def validate_user(data):
required_fields = ["username", "email", "password"]
return all(field in data and data[field] for field in required_fields)
user = {"username": "alice", "email": "alice@example.com", "password": "secret"}
print(validate_user(user))
# True
incomplete_user = {"username": "alice", "email": "alice@example.com"}
print(validate_user(incomplete_user))
# False
Checking if all numbers are positive
numbers = [1, 2, 3, 4, 5]
all_positive = all(x > 0 for x in numbers)
print(all_positive)
# True
numbers_with_negative = [1, 2, -3, 4, 5]
all_positive = all(x > 0 for x in numbers_with_negative)
print(all_positive)
# False
Short-circuit behavior
# all() stops at the first False - useful for expensive computations
def is_valid(x):
print(f"Checking {x}")
return x > 0
results = [1, 2, -1, 3]
print(all(is_valid(x) for x in results))
# Checking 1
# Checking 2
# Checking -1
# False
Edge Cases
- Empty iterable: Returns
True(vacuous truth) - Non-iterable: Raises
TypeError - None: Raises
TypeError
# Empty list - returns True
print(all([]))
# True
# Raises TypeError
# all(42) # TypeError: argument is not iterable
See Also
- built-in::any — returns True if any element is truthy
- built-in::bool — converts a value to boolean
- built-in::filter — filter elements based on a condition