Lists · Class 11 · CBSE · Science Computer Science

What is the output of the following Python code? numbers = [3, 1, 2]; result = numbers.sort(); print(result, numbers)

Practice question from Lists (Class 11 · CBSE · Science Computer Science), with the correct answer and a step-by-step solution.

medium · MCQ · Q-6B19A5

What is the output of the following Python code? numbers = [3, 1, 2]; result = numbers.sort(); print(result, numbers)

  1. A.None [1, 2, 3]Correct answer
  2. B.[1, 2, 3] None
  3. C.[3, 1, 2] None
  4. D.None [3, 1, 2]

Solution

The sort() method changes the list in place and returns None. Thus, result is None and numbers becomes [1, 2, 3].

More from Lists

All of Lists

Practise more Computer Science

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed