ProgrammingHardTCS NQT · Wipro pattern

What is printed?

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

Correct answer: C. [2]

The extended slice ::2 selects indices 0 and 2, and deleting them leaves only the item at index 1.

More Python Programming questions

Exams that ask this topic