Python all() Function
The Python all() function returns true when boolean value of all elements of an iterable are true, else returns false. An iterable object can be any data structure like list, tuple, set, string, dictionary and range() function etc. and boolean value of an element of iterable is always true unless:
- The element is False
- The element is 0
- The element is None
Syntax
all(iterable)
Parameters
iterable |
Required. iterable object like list, tuple, set, string , dictionary and range() etc. |
Example:
In the example below, all() function returns true when boolean value of all elements of a list are true.
MyString = "Hello" print(all(MyString)) MyList = [] print(all(MyList)) MyTuple = (None, 0, 1) print(all(MyTuple))
The output of the above code will be:
True True False
Please note that, for empty iterable, all() function returns True value.
❮ Python Built-in Functions