Home / Python / Reference / Built-in functions

Python any() function

True if at least one item is truthy.

Syntax

any(iterable)

Stops as soon as it finds a True item. Often used with a generator expression to ask "is there any …?".

Parameters

iterableitems to test

Return value

bool

Example

Code

temps = [24, 29, 33, 27]
print(any(t > 30 for t in temps))
print(any([]))                 # False: nothing is true
print(any(["", 0, None, "x"]))

Output

True
False
True

Related

Learn it step by step in the free lesson Pythonic Python, with exercises that check your answers.