What does all mean in Python?

Better Stack Team
Updated on February 3, 2023

In Python, the all() function returns True if all elements of an iterable (e.g. list, tuple, etc.) are true, and False otherwise. For example:

 
>>> all([True, True, True])
True
>>> all([True, False, True])
False

An empty iterable returns True.

 
>>> all([])
True

It can also be used on a generator object.

 
>>> all(i > 2 for i in [1, 2, 3, 4])
False

It is equivalent to the following code:

 
>>> def all(iterable):
...     for element in iterable:
...         if not element:
...             return False
...     return True