Function signature:
all(iterable)
Parameters:
iterable - A Python iterable. The containers list, tuple, set, dictionary and any object that support the iterable protocol of Python are collectively called iterables.
Return value:
Returns a Boolean value.
True when each of the elements in the iterable evaluates True or when len(iterable) is zero. Returns False otherwise.
Overview:
- The all() function checks whether a Python iterable object has all of its elements evaluate to True. For example, a Python list object with some of its elements as None makes the all() method return False.
- If the iterable object is empty, the all() function returns True.
- This behaviour is the opposite of any() function where any() will return True if any of the elements of an iterable evaluate to True.
Example:
# Example Python program that checks few iterables - a list # List with numbers and None # An empty list # A tuple |
Output:
False True True |