What is the output of the following Python code? a = ; b = a.sort(); print(a, b)
Correct answer B. [1, 2, 3] None
Explanation
list.sort() sorts the list in place and returns None, a convention Python uses for methods that mutate an object. So a becomes [1, 2, 3] while b is None. If you need a new sorted list and want to keep the original, use the built-in sorted(a) instead.
Answer checked How we write and check questions
Discussion