ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(sorted([True, 2, 1.5, False, -1]))
  1. A. [False, -1, True, 1.5, 2]
  2. B. [-1, False, 1.5, True, 2]
  3. C. [-1, False, True, 2, 1.5]
  4. 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

Exams that ask this topic