ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print(list(reversed(range(3))), list(range(3))[::-1] == list(reversed(range(3))), list(range(3, 0, -1)))
  1. A. [2, 1, 0] False [3, 2, 1]
  2. B. [2, 1, 0] True [3, 2, 1]
  3. C. [0, 1, 2] True [3, 2, 1]
  4. D. [2, 1, 0] True [2, 1, 0]

Correct answer: B. [2, 1, 0] True [3, 2, 1]

reversed and slicing with -1 both give the reversed order, so the comparison is True. range(3, 0, -1) counts down from 3 to 1, so it includes the start but not the stop.

More Python Programming questions

Exams that ask this topic