Q. What is the difference between sort() and sorted()?
Answer =
The sort() method modifies the list it is called on. That is, the sorted list is stored in the same list; a new list is not created. While the sorted() function creates a new list containing a sorted version the list passed to it as argument. It does not modify the list passed as a parameter.
The sort() method works on a list and modifies it. While the sorted() function can take any iterable sequence type, such as a list or a tuple etc., and it always returns a sorted list irrespective of the type of the sequence passed to it
The sort() method does not return anything (no return value); it modifies the list in place. While the sorted() function returns a newly created sorted list; it does change the passed sequence.
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )