Skip to content
Home » Python Programs » Python Program to Reverse a Tuple

Python Program to Reverse a Tuple

Python Program to Reverse a Tuple. This tuple reverse program is not only for particular data types in python program, it works for every data type in tuple. Reversing a list in the middle of it. reverse() is a function that allows you to reverse the direction of To make a reversed copy, use the “ [::-1] ” list slicing technique. Using the reversed() built-in method to create a reverse iterator.

Tuple Method in Python

A tuple is a collection of ordered and immutable items. Tuples, like lists, are sequences. Tuples and lists differ in that tuples cannot be altered, although lists may, and tuples use parentheses whilst lists use square brackets. Tuples are a type of variable that allows you to store several elements in a single variable. 

Tuple is one of Python’s four built-in data types for storing collections of data; the other three are List, Set, and Dictionary, all of which have different properties and applications. A tuple is a collection of items that is both ordered and immutable.

Reversed() Function in Python

The reversed() function in Python returns an iterator that accesses the specified sequence backwards. Slicing can be used to reverse strings. To reverse a string, simply create a slice that starts at index 0 and finishes at the length of the string. Python List reverse() is a built-in method in the Python programming language for reversing List objects in place. 

Python Program to Reverse a Tuple

a = ("Inlarn.com")
b = reversed(a)
print(tuple(b))
a = (1,45,67,65)
b = reversed(a)
print(tuple(b))

Output:

(‘m’, ‘o’, ‘c’, ‘.’, ‘n’, ‘r’, ‘a’, ‘l’, ‘n’, ‘I’)

(65, 67, 45, 1)