Write a Python program to check whether an element exists within a tuple


The program defines a tuple t containing 11 elements, including characters and an integer.

The program then uses the in operator to check for the presence of various values in the tuple. The in operator returns True if a specified value is found in the tuple, and False otherwise.

  • The first expression 't' in t checks if the character 't' is in the tuple t. The result of this expression is True, as the character 't' is present in the tuple.
  • The second expression 8 in t checks if the integer value 8 is in the tuple t. The result of this expression is also True, as the integer value 8 is present in the tuple.
  • The third expression 'x' in t checks if the character 'x' is in the tuple t. The result of this expression is False, as the character 'x' is not present in the tuple.
  • The fourth expression 2 in t checks if the integer value 2 is in the tuple t. The result of this expression is also False, as the integer value 2 is not present in the tuple.
  • Finally, the results of the four in operator expressions are printed to the console using the print() function.

Source Code

t = ('T', 'u', 't', 'o', 'r', ' ', 'J', 'o', 'e', 's',8)
print('t' in t)
print(8 in t)
print('x' in t)
print(2 in t)
 

Output

True
True
False
False

Example Programs