Difference between list.sort() and sorted() in 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 returnsNone
. -
sorted
returns a list without modification on the original list.
Reference
Python tools
Share on: