In other languages:
temp = a a = b b = temp
In Python:
b, a = a, b
Perhaps you've seen this before. But do you know how it works?
- The comma is the tuple constructor syntax.
- A tuple is created on the right (tuple packing).
- A tuple is the target on the left (tuple unpacking).
This is vald for lists aswell
Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.
No comments:
Post a Comment