QuestenaPractice that shows what to review next
Question 3

After `a = 2`, `b = 5`, and `a, b = b, a`, what are the values of `a` and `b`?

  1. `a` is 2 and `b` is 2.
  2. `a` is 5 and `b` is 5.
  3. `a` is 5 and `b` is 2.Correct answer
  4. The swap raises an assignment error.

Explanation

Python obtains both right-hand values before rebinding either target, so the old value of `b` goes to `a` and the old value of `a` goes to `b`. A left-to-right update would lose one old value, but that is not how multiple assignment is evaluated.

Continue with this test

Start practice
Question 3: After `a = 2`, `b = 5`, and `a, b = b, a`, what are the… · Python Fundamentals · Questena