![]() |
VOOZH | about |
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.
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.
True
Explanation:
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.
True
Explanation:
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.
True
Explanation: