w3resource

Python Exercise: Repeated items of a tuple


Write a Python program to find repeated items in a tuple.

Visual Presentation:

Python Tuple: Repeated items of a tuple.

Sample Solution:

Python Code:

# Create a tuple containing a sequence of numbers
tuplex = 2, 4, 5, 6, 2, 3, 4, 4, 7
# Print the contents of the 'tuplex' tuple
print(tuplex)

# Count the number of times the value 4 appears in the 'tuplex' tuple
count = tuplex.count(4)
# Print the count of how many times 4 appears
print(count) 

Sample Output:

(2, 4, 5, 6, 2, 3, 4, 4, 7)                                                                                   
3   

Flowchart:

Flowchart: Repeated items of a tuple

Python Code Editor:

Previous: Write a Python program to create the colon of a tuple.
Next: Write a Python program to check whether an element exists within a tuple.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.