ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
b = [3, 1, 2]
a = b.sort()
c = sorted(b, reverse=True)
print(a, b, c)
  1. A. [1, 2, 3] [1, 2, 3] [3, 2, 1]
  2. B. None [3, 1, 2] [3, 2, 1]
  3. C. None [1, 2, 3] [3, 2, 1]
  4. D. [1, 2, 3] None [3, 2, 1]

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

list.sort sorts in place and returns None, so a is None. sorted returns a new list, and reverse=True gives the descending copy.

More Python Programming questions

Exams that ask this topic