DEV Community

Discussion on: How can you swap two variables without using a third?

Collapse
 
leneko profile image
leNEKO

In python

b = a ^ b
a = a ^ b
b = b ^ a

am i right ?

Collapse
 
leneko profile image
leNEKO • Edited

oh shorter,

b ^= a
a ^= b
b ^= a
Collapse
 
leneko profile image
leNEKO

So now, what is the second step ? :)