The any() function returns True if any element of an iterable is True. If not, it returns False.
Example
any() Syntax
The syntax of any() is:
any(iterable)
any() Parameters
The any() function takes an iterable (list, string, dictionary etc.) in Python.
any() Return Value
The any() function returns a boolean value:
Trueif at least one element of an iterable is trueFalseif all elements are false or if an iterable is empty
| Condition | Return Value |
|---|---|
| All values are true | True |
| All values are false | False |
| One value is true (others are false) | True |
| One value is false (others are true) | True |
| Empty Iterable | False |
Example 1: Using any() on Python Lists
Output
True False True False
The any() method works in a similar way for tuples and sets like lists.
Example 2: Using any() on Python Strings
Output
True True False
Example 3: Using any() with Python Dictionaries
In the case of dictionaries, if all keys (not values) are false or the dictionary is empty, any() returns False. If at least one key is true, any() returns True.
Output
False True False False True