Function signature:
any(iterable)
Parameters:
iterable - A Python iterator like list, deque, set and dictionary or any object implementing the Python iterator protocol.
Return value:
Returns a Boolean value.
True when any of the elements from the iterabale is True. Returns False otherwise.
Overview:
- The Python built-in function any() checks whether a Python iterable object has at least one of its elements evaluating to True.
- For example, a Python list object with only one element evaluating to True and all other elements as None will return True. If the iterable is empty the any() function will return False.
- This behaviour is the opposite of all() function where all() will return True only if all the elements of an iterable evaluate to True.
Example:
# Example Python program that finds whether any of the # Check a list which is sparsely populated with True values # Try an empty list # List without any values evaluating to True |
Output:
True False False |