ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: B. [0, False, True, 2]

sorted is stable, and 0 equals False, so the 0 that appears earlier in the input comes first. True equals 1 and comes before 2.

More Python Programming questions

Exams that ask this topic