Learning something new every day
by David North on Oct.26, 2008, under Code, Facebook, Life
Here’s one for all you progammers out there: what happens to the values of x and y if you type the following in, say, Python?
>>> x = 5
>>> y = 6
>>> x,y = y,x
I’d always half-thought, without really considering it, that you’d end up with x=6 and y=6, i.e. that the above was syntactic sugar for:
>>> x = y
>>> y = x
Actually, though, it turns out…
>>> x=5
>>> y=6
>>> x,y=y,x
>>> print x,y
6 5
Leave a Reply
You must be logged in to post a comment.