Python Exercise: Check whether an element exists within a tuple
Python tuple: Exercise-10 with Solution
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.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/python-exercises/tuple/python-tuple-exercise-10.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics