ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
l = [1, 2, 3, 4, 5]
l[1:4] = []
print(l)
  1. A. [1, 5]
  2. B. [1, 2, 3, 4, 5]
  3. C. []
  4. D. [1, None, None, None, 5]

Correct answer: A. [1, 5]

Assigning an empty list to the slice l[1:4] deletes elements at indices 1, 2, 3 (values 2, 3, 4), leaving [1, 5].

More Python Programming questions

Exams that ask this topic