Reputation: 55
I have two tuples:
tup_1 = ('hello', 'world')
tup_2 = (1, 2, 3)
printing both on the same line, I get:
('hello', 'world') (1, 2, 3)
I want to swap the values of tup_1
and tup_2
so that when I now print them on the same line, I get:
(1, 2, 3) ('hello', 'world')
How can I do this?
Upvotes: 1
Views: 5059
Reputation: 239693
You can swap the tuples, just like any other objects,
>>> 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')
Upvotes: 5