我有两个元组:
tup_1 = ('hello', 'world')
tup_2 = (1, 2, 3)
在同一行打印,我得到:
('hello', 'world') (1, 2, 3)
我想交换 tup_1 和 tup_2 的值,这样当我现在在同一行打印它们时,我得到:
(1, 2, 3) ('hello', 'world')
我该怎么做?
请您参考如下方法:
您可以交换元组,就像任何其他对象一样,
>>> print tup_1, tup_2
('hello', 'world') (1, 2, 3)
>>> tup_1, tup_2 = tup_2, tup_1
>>> print tup_1, tup_2
(1, 2, 3) ('hello', 'world')
