ProgrammingModerateTCS NQT · Infosys

Which statement about sorting in Python is correct?

  1. A. list.sort() sorts in place and returns None, while sorted() returns a new list
  2. B. list.sort() returns the sorted list, while sorted() sorts in place
  3. C. sorted() changes the original list and returns None
  4. D. sorted() is stable but list.sort() is not

Correct answer: A. list.sort() sorts in place and returns None, while sorted() returns a new list

list.sort is a method that mutates the list and returns None. sorted accepts any iterable and returns a new list, and both sorts are stable.

More Python Programming questions

Exams that ask this topic