Checking Element Existence in Tuple

Write a Python program to check whether an element exists within a tuple. Return True if the element exists, else return False.

Example 1:

Input: (5, 'hello', 8.3, 'world', 9, 'a', 'b', 6, 1), 'world' 
Output: True

Example 2:

Input: (7, 'world', 3.14, 'd', 'new', 10, 'end', 9, 2), 'not there' 
Output: False

You can use the ‘in’ operator to check if an element exists in a tuple.

def check_existence(t, element):
    return element in t

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!