Python - Reversing a Tuple Last Updated : 19 Feb, 2025 Comments Improve Suggest changes 8 Likes Like Report We are given a tuple and our task is to reverse whole tuple. For example, tuple t = (1, 2, 3, 4, 5) so after reversing the tuple the resultant output should be (5, 4, 3, 2, 1).Using SlicingMost common and Pythonic way to reverse a tuple is by using slicing with a step of -1, here is how we can do it: Python t = (1, 2, 3, 4, 5) # Reverse the tuple using slicing with a step of -1 rev = t[::-1] print(rev) Output(5, 4, 3, 2, 1) Explanation:t[::-1] creates a new tuple by iterating through t in reverse order.Original tuple t remains unchanged and reversed tuple is stored in rev.Using reversed()reversed() function returns an iterator that can be converted to a tuple. Python t = (1, 2, 3, 4, 5) # Reverse the tuple using the built-in reversed() function and convert it back to a tuple rev = tuple(reversed(t)) print(rev) Output(5, 4, 3, 2, 1) Explanation:reversed(t) returns an iterator that iterates through tuple in reverse order.tuple(reversed(t)) converts reversed iterator into a new tuple without modifying the original tuple.Using a LoopWe can manually reverse the tuple by iterating from the end using a loop. Python t = (1, 2, 3, 4, 5) # Reverse the tuple by iterating through the indices in reverse order rev = tuple(t[i] for i in range(len(t) - 1, -1, -1)) print(rev) Output(5, 4, 3, 2, 1) Explanation:range(len(t) - 1, -1, -1) generates indices from the last element to the first, allowing element access in reverse order.Generator expression collects these elements into a new tuple ensuring the original tuple remains unmodified.Using collections.dequeIn this method we are using collections.deque, which provides a reverse() method for in-place reversal of the tuple. Python from collections import deque t = (1, 2, 3, 4, 5) deq = deque(t) # Reverse the deque in place deq.reverse() # Convert the reversed deque back to a tuple rev = tuple(deq) print(rev) Output(5, 4, 3, 2, 1) Explanation:deque(t) allows efficient in-place reversal with its reverse() method avoiding the need for additional looping or slicing.tuple(deq) converts the reversed deque back to a tuple ensuring the result is a new tuple while leaving the original tuple unmodified. Comment C chinmoy lenka Follow 8 Improve C chinmoy lenka Follow 8 Improve Article Tags : Python python-tuple Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like