ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
try:
    print(sorted([3, None, 1]))
except TypeError as e:
    print(e)
  1. A. [1, 3, None]
  2. B. '<' not supported between instances of 'int' and 'NoneType'
  3. C. [None, 1, 3]
  4. D. '<' not supported between instances of 'NoneType' and 'int'

Correct answer: D. '<' not supported between instances of 'NoneType' and 'int'

sorted compares the second element with the first first, so it evaluates None < 3, which is not supported. The message names NoneType on the left.

More Python Programming questions

Exams that ask this topic