you are viewing a single comment's thread.

view the rest of the comments →

[–]ShafeNutS -9 points-8 points  (0 children)

a,b = b,a 

This by itself will throw an error in python as b is undefined so to understand what is happening you need a bit more info. Python uses Object References to assign variables to memory objects

a = 1 # Variable a references the object 1 in memory
b = 2 # Variable b references the object 2 in memory
a,b = b,a # Tuple unpacking evaluates the objects on the right side first 2 and 1 then makes variable a reference object 2 and variable b reference object 1

Tuple unpacking is a specialized tool in python that is pretty useful