Last updated on August 8, 2022
In this tutorial, you will learn about the Python all() function with the help of examples.
The all()
function returns True if all items in an iterable are true, otherwise, it returns False. If the iterable object is empty, the all()
function also returns True.
The syntax of the all()
function looks like this:
all(iterable)
Where an iterable object may be a list, tuple, or dictionary.
Examples:
# Check if all items in a list are True
mylist = [0, 1, 1]
x = all(mylist)
print(x)
# Returns False because 0 is the same as False
# Check if all items in a tuple are True:
mytuple = (0, True, False)
x = all(mytuple)
print(x)
# Returns False because both the first and the third items are False
Comments are closed, but trackbacks and pingbacks are open.