ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
a, b = 1, 2
a, b = b, a + b
c = [3, 4]
c[0], c[1] = c[1], c[0]
m, n = n, m = 7, 8
print(a, b, c, m, n)
  1. A. 2 3 [4, 3] 8 7
  2. B. 2 4 [4, 3] 7 8
  3. C. 2 3 [4, 4] 8 7
  4. D. 2 3 [4, 3] 7 8

Correct answer: A. 2 3 [4, 3] 8 7

Tuple assignment evaluates the right side first: (a, b) = (2, 1 + 2). The chained assignment assigns the tuple (7, 8) to `m, n` first and then to `n, m`, leaving n = 7 and m = 8.

More Python Programming questions

Exams that ask this topic