Difference between list.sort() and sorted() in Python

Posted by Bruce Liu on May 27, 2020

🏷️ Tags: python

There are 3 main differences between list.sort() and sorted().

What is it?

  • sort is a method of list.

  • sorted is a bult-in function.

Suitable object

  • sort is only for lists.

  • sorted can be used for any iterable.

Returns

  • sort sorts the original list in-place and returns None.

  • sorted returns a list without modification on the original list.

Reference


Share on:

« PREVIOUS: Get started with Selenium
NEXT: First release of adaptive-curvefitting »