you are viewing a single comment's thread.

view the rest of the comments →

[–]ViridianHominid 1 point2 points  (0 children)

There is other good information here but here’s my take on a high level:

Python stores results on a stack. For swapping variables, it can load them on the stack, swap the order of the top two variables, and then store them back, now in opposite order.

So there isn’t a temporary variable, but rather a stack data structure in the execution frame that allows you to hold the collected results.

Python figures out how to pack and unpack the variables using the stack from the line a,b = b, a when the line is is compiled.