ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
a, b = 1, 2
a, b = b, a + b
print(a, b)
  1. A. 2 1
  2. B. 1 3
  3. C. 2 3
  4. D. 3 2

Correct answer: C. 2 3

The right-hand side (b, a+b) = (2, 1+2=3) is fully evaluated using the OLD values of a and b before any assignment happens, then unpacked: a becomes 2, b becomes 3.

More Python Programming questions

Exams that ask this topic