Python any() Function

Python Python Basic

any() is a Python built-in function to return True if any element of the iterable argument is True. It return False if the iterable argument is empty.

Example 1 - any() with the list has True value

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

True

Example 2 - any() with list of all True values

data_list = [True, True, True]
x = any(data_list)
print(x)
Output:

True

Example 3 - any() with list of all False values

data_list = [False, False, False]
x = any(data_list)
print(x)
Output:

False

Example 4 - any() with an empty list

data_list = []
x = any(data_list)
print(x)
Output:

False

Example 5 - any() with the set has True value

data_set = {True, False, True}
x = any(data_set)
print(x)
Output:

True

Example 6 - any() with set of all True values

data_set = {True, True, True}
x = any(data_set)
print(x)
Output:

True

Example 7 - any() with set of all False values

data_set = {False, False, False}
x = any(data_set)
print(x)
Output:

False

Example 8 - any() with an empty set

data_set = {}
x = any(data_set)
print(x)
Output:

False

Example 9 - any() with the tuple has True value

data_tuple = (True, True, False)
x = any(data_tuple)
print(x)
Output:

True

Example 10 - any() with tuple of all True values

data_tuple = (True, True, True)
x = any(data_tuple)
print(x)
Output:

True

Example 11 - any() with tuple of all False values

data_tuple = (False, False, False)
x = any(data_tuple)
print(x)
Output:

False

Example 12 - any() with an empty tuple

data_tuple = ()
x = any(data_tuple)
print(x)
Output:

False