ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
a = [5, 3, 5, 1]
a.remove(5)
a.insert(10, 7)
a.insert(-10, 0)
print(a, a.index(5), a.pop(1))
  1. A. [0, 3, 5, 1, 7] 2 3
  2. B. [0, 3, 1, 7] 2 5
  3. C. [3, 5, 1, 7, 0] 1 5
  4. D. [0, 5, 1, 7] 2 3

Correct answer: D. [0, 5, 1, 7] 2 3

remove deletes only the first 5, and out-of-range insert indices clamp to the ends: [0, 3, 5, 1, 7]. print receives the list object itself and formats it only after all arguments are evaluated, by which time pop(1) has removed 3.

More Python Programming questions

Exams that ask this topic