[Tutor] Variable Swap

Steve Nelson sanelson at gmail.com
Mon Jan 29 13:29:32 CET 2007


Hello,

I understand the use of xor to do a variable swap without a temporary variable:

>>> x=2
>>> y=3
>>> y=x^y
>>> x=x^y
>>> y=x^y
>>> x
3
>>> y
2


However, why do I see this?

>>> y=x^y
>>> y
1

S.


More information about the Tutor mailing list