How to invert tuple elements in Python

2 Answers

0 votes
tpl = (1, 2, 3, 4)

inverted_tpl = tpl[::-1]

print(inverted_tpl)


'''
run:

(4, 3, 2, 1)

'''

 



answered Jan 15 by avibootz
0 votes
tpl = (1, 2, 3, 4)

inverted_tpl = tuple(reversed(tpl))

print(inverted_tpl)


'''
run:

(4, 3, 2, 1)

'''

 



answered Jan 15 by avibootz
...