ProgrammingModerateTCS NQT · Accenture

What is printed?

What is printed?
print([i for i in range(10) if i % 3 == 0][::-2])
  1. A. [9, 6, 3, 0]
  2. B. [9, 3, 0]
  3. C. [6, 0]
  4. D. [9, 3]

Correct answer: D. [9, 3]

The comprehension gives 0, 3, 6 and 9, and the slice with step -2 starts at the end and skips every other item, which gives 9 and 3.

More Python Programming questions

Exams that ask this topic