ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(max(['10', '9'], key=len), max(['10', '9']), max([10, 9], key=str))
  1. A. 10 10 9
  2. B. 10 9 10
  3. C. 10 9 9
  4. D. 9 9 9

Correct answer: C. 10 9 9

With key=len, '10' is the longest. Plain max compares strings, so '9' is larger than '10'. With key=str, the integer 9 is compared as the text '9', which beats '10'.

More Python Programming questions

Exams that ask this topic