In Python we can swap values between two variable a and b this way:

a = 3; b = 7
print(a, b)   # =====> 3  7

a, b = b, a  # swapping!
print(a, b)   # =====> 7  3

How does this work?

If I split the 'magic' line into:
a = b; b = a
without a temp variable I get:
print(a, b)   # =====> 7  7

Thank you,
Yehuda (Israel)
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to