Home ยป Check Item exists in a Tuple in Python

Check Item exists in a Tuple in Python

In this example we check to see if an item exists in a tuple

We use the in operator to find the item that exists in a tuple.

Example

number_tuple = (10, 20, 30, 40, 50, 60, 70, 80, 90)
print("Tuple Items = ", number_tuple)

number = int(input("Enter Tuple Item to Find = "))

result = number in number_tuple

print("Does the tuple contain ", number, "? ", result)

When you run this you will see something like this

here are 2 runs

>>> %Run checktuple.py
Tuple Items =  (10, 20, 30, 40, 50, 60, 70, 80, 90)
Enter Tuple Item to Find = 10
Does the tuple contain  10 ?  True
>>> %Run checktuple.py
Tuple Items =  (10, 20, 30, 40, 50, 60, 70, 80, 90)
Enter Tuple Item to Find = 11
Does the tuple contain  11 ?  False

You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More