Python: swapping variables

I forgot where I read this, but this is a neat way of swapping variables in python:


u = 1
v = 2
print "%i %i" % (u, v)
u, v = v, u
print "%i %i" % (u, v)

Leave a Reply

Your email address will not be published.