ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
try:
    print(sorted([3, None, 1]))
except TypeError:
    print('TypeError')
print(max(['b', 'a'], key=str.upper), min([[2], [1, 9]]))
  1. A. TypeError | a [2]
  2. B. 3 | b [1, 9]
  3. C. TypeError | b [2]
  4. D. TypeError | b [1, 9]

Correct answer: D. TypeError | b [1, 9]

Python 3 cannot compare None with an int, so sorted raises TypeError. max uses the upper-cased keys and picks b, and lists compare element by element, so [1, 9] is smaller than [2].

More Python Programming questions

Exams that ask this topic