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))
- A. [10, 7, 4, 1] 9 0 True False
- B. [10, 7, 4, 1] 9 0 True True
- C. [10, 7, 4, 1, 0] 9 0 True False
- 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
- What is printed? python print(sum(range(106)) == 106 (106 - 1) // 2, 20.5 20.5 == 2.0, 20.5 20.5)
- What is printed? python print(int(2.9999999999999996), float('1e400'), -float('1e400'), 1e308 10 == float('inf'))
- What is printed? python print(10 % 3.5, -10 % 3.5, 10 // 3.5, round(-1.5), round(0.5) + round(1.5))
- What is printed? python print(divmod(7.5, 2), 7.5 % -2, -7.5 // 2)
- What is printed? python print(f'{0.1:.20f}'[:12], f'{2/3:.3f}', f'{1e22:.0f}', f'{1e23:.0f}')
- What is printed? python print(float(' 10.5 '), float('infinity'), float('-nan') != float('-nan'), float('10'))