In this example, you will define tuple and reverse it with different methods.
You can reverse a tuple using various logic but here is common two methods for reverse a tuple in python :
Example 1 : Reverse tuple using the technique of slicing
# python program for reverse tuple using slicing
#define tuple
tpl = (1,34,23,43,75,90)
tpl = tpl[::-1]
for i in tpl:
print(i)
Output :
90
75
43
23
34
1
Example 2 : Reverse tuple using reversed method
# python program for reverse tuple using reversed method
#define tuple
tpl = (1,34,23,43,75,90)
tpl = tuple(reversed(tpl))
for i in tpl:
print(i)
Output :
90
75
43
23
34
1
Ask anything about this examples