ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
try:
    print(sorted([3, None, 1]))
except TypeError:
    print('cannot compare')
  1. A. [None, 1, 3]
  2. B. cannot compare
  3. C. [1, 3, None]
  4. D. TypeError

Correct answer: B. cannot compare

Python 3 does not order None against numbers, so sorted raises TypeError. The except branch prints the message, and TypeError itself is not printed.

More Python Programming questions

Exams that ask this topic