transformation

any()

Returns True if any element of the iterable is truthy. Short-circuits on the first truthy value.

any(iterable)

Parameters

Parameter Purpose
iterable Iterable of values tested for truthiness
returns True if any element truthy; False for an empty iterable

Examples

any([0, '', False, 1])

Returns True

any([0, '', None])

Returns False

any(x > 10 for x in [1, 5, 20])

Returns True (short-circuits at 20)

Gotcha

any([]) returns False, not True. Combine with a generator expression for lazy predicate checking.

Related built-ins

← All Python built-ins