ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: A. '<' not supported between instances of 'str' and 'int'

For two elements Timsort compares the second with the first, so it evaluates 'a' < 3. Mixed types that cannot be ordered raise TypeError, and the message names the operands in the order they were compared.

More Python Programming questions

Exams that ask this topic