ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(sorted([2.0, 2, True, 1.5]))
  1. A. [True, 1.5, 2, 2.0]
  2. B. [True, 1.5, 2.0, 2]
  3. C. [1.5, True, 2.0, 2]
  4. D. [2, 2.0, True, 1.5]

Correct answer: B. [True, 1.5, 2.0, 2]

True compares as 1, so it comes first. 2.0 and 2 compare equal, and the stable sort keeps their input order, with 2.0 before 2.

More Python Programming questions

Exams that ask this topic