2010-04-19

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)

No comments:

Post a Comment