w3resource logo
Python Exercises

Python Exercise: Reverse a tuple

Python tuple: Exercise-18 with Solution

Write a Python program to reverse a tuple.

Sample Solution:-

Python Code:

>>> #create a tuple
>>> x = ("w3resource")
>>> # Reversed the tuple
>>> y = reversed(x)
>>> print(tuple(y))
>>> #create another tuple
>>> x = (5, 10, 15, 20)
>>> # Reversed the tuple
>>> y = reversed(x)
>>> print(tuple(y))

Sample Output:

('e', 'c', 'r', 'u', 'o', 's', 'e', 'r', '3', 'w')                                                            
(20, 15, 10, 5) 

Python Code Editor:

#create a tuple
x = ("w3resource")
# Reversed the tuple
y = reversed(x)
print(tuple(y))
#create another tuple
x = (5, 10, 15, 20)
# Reversed the tuple
y = reversed(x)
print(tuple(y))

Improve this sample solution and post your code through Disqus