ProgrammingVery hardJEE Advanced · CAT placement

What is printed?

What is printed?
print(sorted([0.5, -0.0, 0.0, -1]))
  1. A. [-1, 0.0, -0.0, 0.25]
  2. B. [-1, -0.0, 0.5, 0.0]
  3. C. [0.5, -0.0, 0.0, -1]
  4. D. [-1, -0.0, 0.0, 0.5]

Correct answer: D. [-1, -0.0, 0.0, 0.5]

-0.0 and 0.0 compare equal, so sorted keeps their input order: -0.0 came first. Printing shows the sign of the zero, but the sort does not treat the two zeros differently.

More Python Programming questions

Exams that ask this topic