Google News
logo
Python Program to Check if a Tuple item exists
To check if a tuple item exists in Python, you can use the `in` keyword or the `count()` method.

Here's an example program that demonstrates both methods :
Program :
my_tuple = ("apple", "banana", "cherry")

# Check if "banana" exists using 'in' keyword
if "banana" in my_tuple:
    print("Yes, 'banana' is in the tuple.")

# Check if "orange" exists using 'in' keyword
if "orange" in my_tuple:
    print("Yes, 'orange' is in the tuple.")
else:
    print("No, 'orange' is not in the tuple.")

# Check if "apple" exists using the count() method
count = my_tuple.count("apple")
if count > 0:
    print("Yes, 'apple' exists in the tuple.")
else:
    print("No, 'apple' does not exist in the tuple.")
Output :
Yes, 'banana' is in the tuple.
No, 'orange' is not in the tuple.
Yes, 'apple' exists in the tuple.