any()

The any() built-in function takes in an iterable object such as a list or tuple and returns True if any of the elements in the iterable are true. If none of the elements present in the iterable are true, any() will return False.

Syntax

any(iterable)

Example 1

Use any() to check if there is a True statement in a list [True, 0, False]:

print(any([True, 0, False]))
// Output: True

Example 2

Use any() to check if there is a True statement in a dictionary:

my_dict = {1 : "On"}
print(any(my_dict))
// Output: True

The Function

The any() built-in function is essentially:

def any(iterable):
for element in iterable:
if element:
return True
return False

Codebyte Example

Edit this page on GitHub

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn Python on Codecademy

Edit this page on GitHub

Contributors