Python any() Function
Example
Check if any item in the list is True:
mylist = [False, True, False] x = any(mylist)
Definition and Usage
If any item in the iterable is true, the any() function returns True, otherwise it returns False.
If the iterable is empty, the any() function will return False.
Syntax
any(iterable)
Parameter Value
Parameter | Description |
---|---|
iterable | Iterable Objects (list, tuple, dictionary) |
More Examples
Example
Check if any item in the tuple is True:
mytuple = (0, 1, False) x = any(mytuple)
Example
Check if any item in the set is True:
myset = {0, 1, 0} x = any(myset)
Example
Check if any item in the dictionary is True:
mydict = {0 : "Apple", 1 : "Orange"} x = any(mydict)
Note:When used on a dictionary, the any() function will check if any keys are true, not values.
Related Pages
Reference Manual:all() Function