Difference between methods and functions (sort)

I just got to the section about lists where they discuss sorting. I thought I understood the difference between methods and functions but .sort() throws me for a loop.

Why couldn’t .sort() be sort()?

Python does have a built-in for sorting any object that supports sorting, sorted(). It creates a copy then sorts it and returns it. list.sort() sorts in place the list in context. It has no return value and can only be used on lists since it is an attribute of the list class.

3 Likes

You’re totally right, I just got to the next unit which goes over sorted(). Thanks!

2 Likes