ProgrammingVery hardTCS NQT · Accenture

What is printed?

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

Correct answer: A. [False, 0.5, 1.0, True, 1]

True, 1 and 1.0 compare equal, so sorted keeps their input order: 1.0, then True, then 1. The 0.5 sits between 0 and 1, and False is the smallest value.

More Python Programming questions

Exams that ask this topic