Python any() Function
Returns True
if any items in an iterable (a list, tuple, or dictionary) are
True
. If the iterable is empty then this function returns False
.
Syntax
Python
Copy Code
any(iterable)
Parameters
Parameter | Description |
---|---|
iterable |
Required. The iterable whose items are to be tested |
Example
Python
Copy Code
anyTrue = any([1, True, 0]) print(f'At least one value in 1, True, and 0 is true: {anyTrue}') anyTrue = any([0, False, 0]) print(f'At least one value in 0, False is true: {anyTrue}') anyTrue = any({'theSkyIsBlue': True, 'theSunIsGreen' : False}) print(f'Some items in the dictionary are true: {anyTrue}') anyTrue = any((True, 1 < 0)) print(f'Some items in the tuple are true: {anyTrue}')
Output
At least one value in 1, True, and 0 is true: True At least one value in 0, False is true: False Some items in the dictionary are true: True Some items in the tuple are true: True