VOOZH about

URL: https://www.geeksforgeeks.org/python/python-check-if-element-is-present-in-tuple/

⇱ Python - Check if element is present in tuple - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python - Check if element is present in tuple

Last Updated : 12 Jul, 2025

We are given a tuple and our task is to find whether given element is present in tuple or not. For example x = (1, 2, 3, 4, 5) and we need to find if 3 is present in tuple so that in this case resultant output should be True.

Using in Operator

in operator checks if an element is present in a tuple by iterating through its items. It returns True if the element is found and False otherwise making it a simple and efficient membership check.


Output
True

Explanation:

  • in operator checks if the element 3 is present in tuple x.
  • If element is found it returns True; otherwise it returns False

Using index()

index() method returns the position of the first occurrence of an element in a tuple. If the element is not found it raises a ValueError so it’s often used with exception handling.


Output
True

Explanation:

  • t.index(3) searches for the element 3 in the tuple t and returns its index if found.
  • If element is not found a ValueError is raised which is caught to set result to False.

Using a Loop

Using a loop we can iterate through each element of the tuple to check for a match. If target element is found we return True otherwise we return False after checking all elements.


Output
True

Explanation:

  • Loop checks each element in the tuple for equality with ele. If a match is found res is set to True.
  • Break statement stops further iteration once the element is found improving efficiency.
Comment