ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(list(range(5, 0, -2)), list(range(0)), range(3)[1:])
- A. [5, 3] [] range(1, 3)
- B. [5, 3, 1] [0] range(1, 3)
- C. [5, 3, 1] [] range(1, 3)
- 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
- What is printed? python print('x'.join('abc'), 'abc'.join('x'))
- What is printed? python print(True + True, 3 True, 'ab' True)
- What is printed? python print('%.3e' % 12345.678)
- What is printed? python print(sorted([3, 1, 2], reverse=True) == [3, 2, 1], [3, 1, 2][::-1])
- What is printed? python print([0] 3 == [0, 0, 0], [[]] 2 == [[], []])
- What is printed? python print(len([x for x in range(100) if x % 7 == 0]), sum(range(0, 100, 7)))