Built-in Functions
any()
Check whether at least one item in an iterable is truthy.
any(iterable)
any() returns True if at least one element in the iterable is truthy.
It short-circuits and returns True immediately upon encountering the first truthy element. Returns False on empty iterables.
Arguments
Parameters
| Name | Description |
|---|---|
| iterable | A collection or other iterable of values to check. |
Result
Returns
True if at least one item is truthy; otherwise False.
Run it
Try it
Run it and change it
answers = [0, "", False] print(any(answers))
Output
Press Run to see what it prints.Worth knowing
- Short-circuit efficiency: Does not evaluate subsequent items once a truthy element is found.