ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(min(map(str, [10, 9, 100])), sorted(['10', '9', '100']), sorted([10, 9, 100]))
  1. A. 9 ['10', '100', '9'] [9, 10, 100]
  2. B. 10 ['9', '10', '100'] [9, 10, 100]
  3. C. 10 ['10', '100', '9'] [10, 9, 100]
  4. D. 10 ['10', '100', '9'] [9, 10, 100]

Correct answer: D. 10 ['10', '100', '9'] [9, 10, 100]

Strings compare character by character, so '10' is the smallest of the strings. Sorting the numbers in strings gives '10', '100', '9', and sorting ints gives 9, 10, 100.

More Python Programming questions

Exams that ask this topic