Predict the output
What does this print?
left, right = "L", "R"
left, right = right, left
print(left, right)Choose an answer, then open Show answer below to check it.
Show answer
Answer: A R L
Right: the right side is evaluated first, then unpacked.
The same tuple swap exchanges node.left and node.right in one line without a temporary.
Why not the others?
- B L R. The tuple assignment does swap the two names.
- C R R. Python builds the tuple (right, left) before assigning, so nothing is overwritten early.