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
  • 671
  • 2
  • 9
  • 17

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
  • 107,083
  • 22
  • 201
  • 376
Thomas Kühn
  • 8,702
  • 3
  • 40
  • 56