ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
x = [0, 1]
i = 0
x[i], i = 5, 1
j = 1
j, x[j] = 0, 7
print(x, i, j)
  1. A. [5, 7] 1 0
  2. B. [7, 1] 1 0
  3. C. [5, 1] 1 0
  4. D. [7, 7] 1 0

Correct answer: B. [7, 1] 1 0

Targets are assigned left to right after the whole right side is evaluated. First x[0] = 5 (i is still 0), then i = 1. Next j = 0 happens before x[j], so x[0] = 7 overwrites the 5.

More Python Programming questions

Exams that ask this topic