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))
- A. [1, 1, 2, 3, 'x', 3, 'y'] 3 3
- B. [1, 1, 2, 3, 'x', 'y'] 'x' 3
- C. [1, 1, 2, 3, 3, 'x', 'y'] 'x' 3
- 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
- What is printed? python print(True + True, sum([True, False, True]), isinstance(True, int), [10, 20, 30][True], 'ab' False == '')
- What is printed? python class Meta(type): def new(m, name, bases, d): d['tag'] = name.lower() return super().new(m, name, bases, d) class…
- What is printed? python print(type(10 / 5))
- Which of these built-in Python types is immutable?
- What is printed? python s = "placement" print(s[2:5])
- What is printed? python print(len({1, 2, 2, 3, 3, 3}))