Skip to content

Python any() Function

Last updated on August 8, 2022

In this tutorial, you will learn about the Python any() function with the help of examples.

The any() function returns True if any item in an iterable is true, otherwise, it returns False. If the iterable object is empty, the any() function will return False, opposite to all() function.

The syntax of the any() function looks like this:

any(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 True because the second item is True

# Check if all items in a tuple are True:
mytuple = (0, True, False)
x = all(mytuple)
print(x)
# Returns True because the second item is True

Comments are closed, but trackbacks and pingbacks are open.