ProgrammingVery hardTCS NQT · Accenture

What is printed?

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

Correct answer: B. [10, 7, 4, 1] [-1, -5, -9] 4 4

range(10, 0, -3) stops before 0, giving 10, 7, 4, 1. The second range stops before -10, and len of range(0, 10, 3) is 4. Indexing a range with -1 gives its last element, 4.

More Python Programming questions

Exams that ask this topic