QuestenaUn entraînement qui indique quoi revoir ensuite
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.Bonne réponse
  4. The swap raises an assignment error.

Explication

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.

Continuer avec ce test

Commencer l’entraînement
Question 3: After `a = 2`, `b = 5`, and `a, b = b, a`, what are the… · Python Fundamentals · Questena