QuestenaÜben und erkennen, was als Nächstes dran ist
Frage 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.Richtige Antwort
  4. The swap raises an assignment error.

Erklärung

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.

Mit diesem Test weitermachen

Übung starten
Frage 3: After `a = 2`, `b = 5`, and `a, b = b, a`, what are the… · Python Fundamentals · Questena