ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(sorted([True, 2, 1.5, False, -1]))
- A. [False, -1, True, 1.5, 2]
- B. [-1, False, 1.5, True, 2]
- C. [-1, False, True, 2, 1.5]
- D. [-1, False, True, 1.5, 2]
Correct answer: D. [-1, False, True, 1.5, 2]
-1 is the smallest, then False (0), then True (1), then 1.5, and 2 last. The booleans compare as the integers 0 and 1.
More Python Programming questions
- What is printed? python print(1 if [] == [] is True else 0, [] is [], () is ())
- What is printed? python print(len(str(float(10300))), str(float(1022))[:4], float(1022) == 1022)
- What is printed? python print(10 // 3, 10 % 3, divmod(10, 3), (10 // 3) 3 + 10 % 3)
- What is printed? python print([1, 2, 3].index(2), 'abc'.index('bc'), (1, 2).index(2), [1, 2, 3].count(4))
- What is printed? python print(float('-0') == 0, str(float('-0')), str(0 -1.0), 0.0 -1)
- What is printed? python print(1 < 2 < 3 < 4 == 4.0, 4 == 4.0 != 5, 1 < 3 > 2 < 2)