Menu Close

Python any() Function

In this python built-in functions tutorial, you will learn all about Python any function along with various examples. This is the best built-in function to check an iterable contains any true or not.
If the iterable contains any true, it returns True otherwise it returns False.

In the previous Python tutorial, we have seen all about Python all function to check whether an iterable contains all true Items or not.

What is Python any() function?

Python any function is a built-in function that returns True if any item in an iterable is true, otherwise, it returns False.


The syntax of any function in python is:-



any function in Python accepts only one parameter that is iterable.

  • iterable:– any iterable object ( list, set, tuple, dictionary etc ) which contains the items.

Return Value

any function in python returns:-

  • True:- If any elements is an iterable is True.
  • False:- If all the elements in an iterable are False.

Python any function example

Here we will take various examples to understand Python any function.

Example 1:

Check if any item in a tuple is false:

x = (False, 1, False)
result = any(x)

Output will be:- True

Example 2:

Check if all the items in a tuple are false:

y = (0, False, 0)
x = all(y)

Output will be:- False

Example 3:

Check if any one item in a set is true:

y = {0, True, 0}
x = any(y)

Output will be:- True

Example 4:

Check if any item in a dictionary is tru:

z = {1 : "Apple", 0 : "Orange"}
x = any(z)

Output will be:- True

Note:- When we use any() function with a dictionary, all function checks only keys of the dictionary, not values.


In this tutorial, you have learned all about Python any() function to check any the item in iterable are true or not. any function in python returns only a boolean value, True or False.

If this tutorial helped you, please keep visiting for further python built-in functions tutorial.

For more information:- Click Here

Python all() function
Python bin() Function

Was this post helpful?

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *