在元组中切换元素最简单(最短)的方法是什么?
my_tuple= (a,b)
切换后:
new_tuple= (b,a)
答案 0 :(得分:0)
通过颠倒它:
>>> my_tuple = ('a', 'b')
>>> new_tuple = my_tuple[::-1]
>>> new_tuple
('b', 'a')
答案 1 :(得分:0)
In [32]: my_tuple= ('a','b')
In [33]: tuple(reversed(my_tuple))
Out[33]: ('b', 'a')