ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
a = [1, 2, 3]
i = 0
i, a[i] = 2, 9
print(a, i)
  1. A. [9, 2, 3] 2
  2. B. [9, 2, 3] 0
  3. C. [1, 2, 9] 2
  4. D. [1, 2, 9] 0

Correct answer: C. [1, 2, 9] 2

The right side is evaluated first; then targets are assigned left to right. i becomes 2 before a[i] is evaluated, so the 9 goes to index 2.

More Python Programming questions

Exams that ask this topic