ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: C. None [1, 2, 3]

list.sort() sorts in place and returns None, so x is None. sorted() returns a new sorted list.

More Python Programming questions

Exams that ask this topic