Python any() built-in function
From the Python 3 documentation
Return True if any element of the iterable is true. If the iterable is empty, return False.
Introduction
The any()
function in Python is a built-in function that checks if at least one element in an iterable is True
. It returns True
if any element evaluates to true, and False
if the iterable is empty or all elements are false. This is useful for quickly determining if a condition is met by any item in a collection.
Examples
# All values are falsy
>>> any([0, '', False])
# False
# Contains one truthy value (2)
>>> any([0, 2, False])
# True
# An empty iterable is considered False
>>> any([])
# False