Python Exercise: Check whether an element exists within a tuple
Write a Python program to check whether an element exists within a tuple.
Visual Presentation:
Sample Solution:
Python Code:
# Create a tuple containing a sequence of items
tuplex = ("w", 3, "r", "e", "s", "o", "u", "r", "c", "e")
# Check if the character "r" is present in the 'tuplex' tuple and print the result
print("r" in tuplex)
# Check if the number 5 is present in the 'tuplex' tuple and print the result
print(5 in tuplex)
Sample Output:
True False
Flowchart:
Python Code Editor:
Previous: Write a Python program to find the repeated items of a tuple.
Next: Write a Python program to convert a list to a tuple.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics