Python any() Function
Instance
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 Instances
Instance
Check if any item in the tuple is True:
mytuple = (0, 1, False) x = any(mytuple)
Instance
Check if any item in the set is True:
myset = {0, 1, 0} x = any(myset)
Instance
Check if any item in the dictionary is True:
mydict = {0 : "Apple", 1 : "Orange"} x = any(mydict)
Comment:When used on a dictionary, the any() function will check if any keys are true, not values.
Related Pages
Reference Manual:all() Function