all Python 3Built-in functionsterm
any
logic
Returns True if at least one element of the iterable is true. Evaluates lazily.
Syntax
any(iterable)
any() gives you a yes-or-no answer and never the element that matched; when you need the element itself, reach for next() over a generator with a default value. Pass a generator expression rather than a list comprehension inside the parentheses — the comprehension builds every result first, so the early exit on the first true item is lost.
Examples
print(any([False,True,False])) # → True
print(any([False,False])) # → False
print(any([])) # → False
print(any(x<0 for x in [1,-1,3])) # → True
print(any(x==5 for x in range(10))) # → True
# ленивое вычисление — остановится на первом True
print(any(x > 100 for x in range(10**6))) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy