ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print(sorted([3, 1, 2], reverse=True) == [3, 2, 1], [3, 1, 2][::-1])
- A. False [2, 1, 3]
- B. True [2, 1, 3]
- C. True [3, 1, 2]
- D. True [1, 2, 3]
Correct answer: B. True [2, 1, 3]
sorted with reverse=True gives 3, 2, 1, which equals the list [3, 2, 1]. The reversed slice of [3, 1, 2] is [2, 1, 3].
More Python Programming questions
- 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)))
- What is printed? python print(round(-2.5), round(-3.5), round(-2.5 - 1e-9))
- What is printed? python print(7 -1 7, (7 -1) 7 == 1.0)
- What is printed? python print(int('0o777', 8) == 511, int('777', 8) - int('0o777', 0))
- What is printed? python print(len('%d' % -0), '%d' % -0.0, '%.1f' % -0.0)