ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
L = list(range(10))
L[2:8:2] = "XYZ"
del L[-3:]
L[len(L):] = [99]
print(L)
  1. A. [0, 1, 'X', 3, 'Y', 5, 'Z', 7, 99]
  2. B. [0, 1, 'XYZ', 3, 5, 7, 99]
  3. C. [0, 1, 'X', 'Y', 'Z', 5, 99]
  4. D. [0, 1, 'X', 3, 'Y', 5, 'Z', 99]

Correct answer: D. [0, 1, 'X', 3, 'Y', 5, 'Z', 99]

The extended slice selects indices 2, 4, 6, which receive X, Y, Z. Deleting the last three removes 7, 8, 9. Assigning to the empty slice at the end appends.

More Python Programming questions

Exams that ask this topic