ProgrammingHardGATE CS · Product-company placement

Which of these expressions raises an exception in Python 3?

  1. A. sorted(['b', 'A', 'a'])
  2. B. max([[], [0]])
  3. C. min((2, 'x'), (1, 5))
  4. D. sorted([3, None, 1])

Correct answer: D. sorted([3, None, 1])

Python 3 does not define ordering between None and int, so sorting [3, None, 1] raises TypeError. Strings order by code point, lists compare lexicographically, and the tuple comparison is decided by the first elements 2 vs 1 before reaching 'x' vs 5.

More Python Programming questions

Exams that ask this topic