[Tutor] Variable Swap

Simon Brunning simon at brunningonline.net
Tue Jan 30 13:40:05 CET 2007

On 1/30/07, Steve Nelson <sanelson at gmail.com> wrote:
> > x, y = y, x
> Doesn't this use temporary variables?

Python doesn't really *have* variables, as such, so no. What it does
is to create a tuple referring to the objects (or just possibly one
object) referred to by the names 'y' and 'x', then re-binds the
objects from the tuple to the names 'x' and 'y' respectively.

Reset your brain! <http://effbot.org/zone/python-objects.htm>

Simon B
simon at brunningonline.net

More information about the Tutor mailing list