any()
any(iterable) Returns:
bool · Updated March 13, 2026 · Built-in Functions built-in iteration boolean validation
The any() function returns True if at least one element in an iterable is truthy. It short-circuits on the first truthy value, making it efficient for checking whether any condition holds across a collection.
Syntax
any(iterable)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
iterable | iterable | — | Any iterable (list, tuple, set, dict, generator, etc.) |
Examples
Basic usage
# At least one element is truthy
numbers = [0, 0, 5, 0]
print(any(numbers))
# True
# All elements are falsy
falsy = [0, 0, 0, 0]
print(any(falsy))
# False
# Empty iterable returns False
empty = []
print(any(empty))
# False
With strings
# Non-empty string is truthy
words = ["", "", "hello", ""]
print(any(words))
# True
# All empty strings
words_all_empty = ["", "", ""]
print(any(words_all_empty))
# False
# Single character is truthy
print(any("a"))
# True
With dictionaries
# At least one truthy key
d = {"a": 0, "b": 1, "c": 0}
print(any(d))
# True
# All falsy keys
d_all_falsy = {"a": 0, "b": 0, "c": 0}
print(any(d_all_falsy))
# False
Common Patterns
Checking if any value meets a condition
numbers = [1, 2, 3, 4, 5]
has_even = any(x % 2 == 0 for x in numbers)
print(has_even)
# True
numbers_all_odd = [1, 3, 5, 7]
has_even = any(x % 2 == 0 for x in numbers_all_odd)
print(has_even)
# False
Validating user input
def has_error(errors):
return any(errors.values())
errors = {"email": None, "password": "Too short", "username": None}
print(has_error(errors))
# True
no_errors = {"email": None, "password": None, "username": None}
print(has_error(no_errors))
# False
Short-circuit behavior
# any() stops at the first True - useful for expensive computations
def check_value(x):
print(f"Checking {x}")
return x > 5
values = [1, 2, 10, 3]
print(any(check_value(v) for v in values))
# Checking 1
# Checking 2
# Checking 10
# True
Edge Cases
- Empty iterable: Returns
False - Non-iterable: Raises
TypeError - None: Raises
TypeError
# Empty list - returns False
print(any([]))
# False
# Raises TypeError
# any(42) # TypeError: argument is not iterable
See Also
- built-in::all — returns True if all elements are truthy
- built-in::bool — converts a value to boolean
- built-in::filter — filter elements based on a condition