Member-only story
Hi everyone, welcome back. Today, we will be going over the all() function in Python and see how it works. The all() function is a built in function and can be used to check if all the values within an iterable object are true values. The all() function returns a boolean value. With this introduction out of the way, let’s get into it.
All() Function
Let’s see how the all() function works:
list = [True, True]
print(all(list))Output:
True
As we can see in the example above, we created a list with only ‘True’ values and are printing the result of the all() function being used on it. Our output verifies that our list does contain all true values. Let’s see what it does if we have a false value:
list = [True, False]
print(all(list))Output:
False
As expected, we have a false in our output, verifying that our list does not contain all true values.
More List Examples
This also works with the numerical values of 0 and 1 as well. 0 being false, and 1 being true. Let’s see some examples. List containing all true values:
list = [1, 1]
print(all(list))Output:
True