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))

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.



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program