ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
a = [0, 1, 2, 3, 4, 5, 6, 7]
del a[::3]
print(a, a[-1:0:-2])
  1. A. [1, 2, 4, 5, 7] [7, 4, 1]
  2. B. [0, 1, 2, 4, 5, 7] [7, 4, 1]
  3. C. [1, 2, 4, 5] [5, 2]
  4. D. [1, 2, 4, 5, 7] [7, 4]

Correct answer: D. [1, 2, 4, 5, 7] [7, 4]

del a[::3] removes indices 0, 3, 6 (values 0, 3, 6), leaving [1, 2, 4, 5, 7]. a[-1:0:-2] starts at index 4 (7), then index 2 (4), and stops before index 0, so 1 is excluded.

More Python Programming questions

Exams that ask this topic