0
>>> a = 5
>>> b = 3
>>> c = 7
>>> a, b, c = 3, a, b
>>> b
5

I am playing around with variable assignments and noticed that when I do multivariable assignments, b is assigned the value of a although I have just assigned a new value of 3 to a. Can someone explain this to me?

Bob
  • 741
  • 2
  • 9
  • 18

1 Answers1

2

You're first packing the three values into a tuple and then unpack that tuple into a, b, and c, respectively, so at the moment that b gets assigned its new value, the value of a does not matter anymore.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Thomas Kühn
  • 9,412
  • 3
  • 47
  • 63