ProgrammingModerateInfosys · Accenture · Capgemini pattern

What is printed?

What is printed?
nums = [3, 1, 2]
print(nums.sort())
  1. A. [3, 2, 1]
  2. B. [3, 1, 2]
  3. C. None
  4. D. [1, 2, 3]

Correct answer: C. None

list.sort() sorts in place and returns None, so the print shows None. Use sorted(nums) to get a new sorted list back.

More Python Programming questions

Exams that ask this topic