Python all() Function

all() is a Python built-in function to return True if all elements of the iterable argument are True or the iterable argument is empty.

Example 1 - all() with list of all True values

data_list = [True, True, True]
x = all(data_list)
print(x)
Output:

True

Example 2 - all() with list of not all True values

data_list = [False, True, True]
x = all(data_list)
print(x)
Output:

False

Example 3 - all() with list of all False values

data_list = [False, False, False]
x = all(data_list)
print(x)
Output:

False

Example 4 - all() with an empty list

data_list = []
x = all(data_list)
print(x)
Output:

True

Example 5 - all() with a set of all True values

data_set = {True, True, True}
x = all(data_set)
print(x)
Output:

True

Example 6 - all() with a set of not all True values

data_set = {True, False, True}
x = all(data_set)
print(x)
Output:

False

Example 7 - all() with a set of all False values

data_set = {False, False, False}
x = all(data_set)
print(x)
Output:

False

Example 8 - all() with an empty set

data_set = {}
x = all(data_set)
print(x)
Output:

True

Example 9 - all() with a tuple of all True values

data_tuple = (True, True, True)
x = all(data_tuple)
print(x)
Output:

True

Example 10 - all() with a tuple of not all True values

data_tuple = (True, True, False)
x = all(data_tuple)
print(x)
Output:

False

Example 11 - all() with a tuple of all False values

data_tuple = (False, False, False)
x = all(data_tuple)
print(x)
Output:

False

Example 12 - all() with an empty tuple

data_tuple = ()
x = all(data_tuple)
print(x)
Output:

True
Tags: