all(iterable)
The all function returns the boolean True if all elements in the iterable passed as an argument are True (or if the iterable is empty), and returns the boolean False otherwise.
This function is equivalent to:
def all(iterable):
for element in iterable:
if not element:
return False
return True
- iterable: iterable to analyze.
If, for example, the iterable is a list, the function will return True only if all its elements are True:
If, on the contrary, any of its elements take the value False, the function will return False:
In the case that the iterable values are not boolean, they are interpreted appropriately. Thus, nonzero numbers are interpreted as True, and zeros as False:
If they are complex numbers, only the number 0 + 0j is interpreted as False:
Continuing with the example of the list, if it is empty, the function returns True: