ProgrammingHardTCS NQT · Wipro pattern

What is printed?

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

Correct answer: C. [5, 3, 1] [] range(1, 3)

range with step -2 counts 5, 3, 1 and stops before 0. An empty range gives an empty list, and slicing a range returns another range object.

More Python Programming questions

Exams that ask this topic