ProgrammingHardGATE CS · Product-company placement

What is printed?

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

Correct answer: A. [10, 7, 4, 1] 9 0 True False

range(0, 6, 2) holds three values and range(0, 7, 2) holds four, so they are different even though they start and step the same way. Ranges compare by the values they produce, not by their start, stop and step arguments.

More Python Programming questions

Exams that ask this topic