Python – Check if Any Item of Tuple is True
To check if any item of a Tuple is True in Python, call any() builtin function and pass the tuple object as argument to it. any() returns True if any the item of Tuple is True, or else it returns False.
Examples
In the following program, we take a tuple x
, and check if at least one its items is True using any() function.
Python Program
x = (False, True, True) result = any(x) print(result)Try Online
Output
True
Now, let us take a tuple with all of its items as False, and check using any() function if any of the item is True.
Python Program
x = (False, False, False) result = any(x) print(result)Try Online
Output
False
ADVERTISEMENT
Conclusion
In this Python Tutorial, we learned how to check if any of the item in Tuple is True in Python, with examples.