ProgrammingVery hardPython · GATE DA · Advanced

What is printed?

What is printed?
a = [1, 2, 3]
a[1:2] = a
a.insert(-1, 'x')
a.insert(99, 'y')
print(a, a.pop(-2), a.index(3))
  1. A. [1, 1, 2, 3, 'x', 3, 'y'] 3 3
  2. B. [1, 1, 2, 3, 'x', 'y'] 'x' 3
  3. C. [1, 1, 2, 3, 3, 'x', 'y'] 'x' 3
  4. D. [1, 1, 2, 3, 'x', 'y'] 3 3

Correct answer: D. [1, 1, 2, 3, 'x', 'y'] 3 3

a becomes [1,1,2,3,3]; insert(-1,'x') goes before the last item; insert(99,'y') appends. print shows the list after pop(-2) has removed the 3, since all arguments are evaluated first.

More Python Programming questions

Exams that ask this topic