Member-only story

Python: Any() Function Tutorial

Jesse L
2 min readDec 25, 2021

--

Hi everyone, welcome back. Today, we will be going over the any() function in Python and see how it works. The any() function is a built in function and can be used to check if any of the values within an iterable object is a true value. The any() function returns a boolean value. With this introduction out of the way, let’s get into it.

Any() Function

Let’s see how the any() function works:

list = [True, False]
print(any(list))
Output:
True

As we can see in the example above, we created a list containing a true value and are printing the result of the any() function being used on it. Our output verifies that our list does contain a true value. Let’s see what it does if we do not have any true values:

list = [False, False]
print(any(list))
Output:
False

As expected, we have a false in our output. verifying that our list does not contain any 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 a true value:

list = [0, 1]
print(any(list))
Output:
True

--

--

Jesse L
Jesse L

Written by Jesse L

Hi, I'm a passionate technology enthusiast and lifelong learner. Beyond my technical pursuits, I'm also passionate about sharing my enthusiasm with others.

No responses yet