Reverse a Tuple
To reverse a Tuple in Python, call reversed() builtin function and pass the tuple object as argument to it. reversed() returns a reversed object. Pass this reversed object as argument to tuple() function. Reversed tuple is ready.
In the following program, we take a tuple
x, and reverse it using reversed() and tuple() functions.
x = (2, 4, 6) result = reversed(x) result = tuple(result) print(result)Try Online
(6, 4, 2)
Now, let us take a tuple of strings, and reverse the tuple.
x = ('apple', 'banana', 'cherry') result = reversed(x) result = tuple(result) print(result)Try Online
('cherry', 'banana', 'apple')
In this Python Tutorial, we learned how to reverse a Tuple in Python, with examples.