Difference between sort() and sorted()

Sort function: It will modify the list it is called on. It modifies the list in-place and has no return value. Only works with list.

Sorted function: Using this function to the list, will create a new list containing a sorted version of the list it is given. This function will not modify the list passed as a parameter. Sorted function sorts any iterable (lists, tuples, string or any such sequence can be iterated over in a for-loop) and returns a new object.

Here is the link regarding sorting: https://docs.python.org/3/howto/sorting.html#sorting-basics


Hey, @pablajaspreet94

You described the behavior correctly. But the definition isn’t correct.

Sort: This is a list method that sorts the current list object.
Sorted: This is a basic python function. Which sorts any iterated object and returns a new object. It doesn’t just work with lists.


I was working with lists while writing this topic. So, wrote accordingly. :smile: Thank you correcting me. I should revise my definition.

Yeah its true it sorts any iterated object.