Python any() Function
The any() function in Python returns a boolean value ‘True’ if any element of the iterable is true or if the iterable is empty, else it returns False.
Syntax
1 2 3 |
any(iterable) |
Parameter
Iterable: An iterable object (list, tuple, dictionary)
Return
This function returns a Boolean value True if any element of the iterable is true or if the iterable is empty, else it returns False.
Example 1
1 2 3 4 5 6 7 8 9 10 |
# Python Program explaining # any() built-in function # Since, all the iterables are false, false is returned print ('The any() function will return: ',any([False, False, False, False])) # item (True) and will return True. print ('The any() function will return: ',any([False, True, False, False, False, True])) # first iterable is True and will return True. print ('The any() function will return: ',any([True, False, False, False, True])) |
Output
1 2 3 4 5 |
The any() function will return: False The any() function will return: True The any() function will return: True |