Well, what do they do differently, and which of those behaviours do you prefer?
It’s not so much a matter of which you should use, but rather finding out what they do and picking one that suits you.
Not sure what the point of the function/exercise is though… the caller can just as well concatenate and sort themselves
You cannot return .sort() because the .sort() method rearranges the list internally and doesn’t return anything. Run it after you combine the lists and then just print your combine list.
Only the sorted() function returns a new list. The sort() function rearranges the existing list. Using sorted we have access to the original list in the original order.
Why does returning lst3.sort() gives an empty list?
When I first sort and then return lst3, it prints the correct result. But when I return lst3.sort() instead, it prints None on the console. Why is that?
lst.sort() is a list method that sorts a list. After you run it, the original list is sorted, period. It is a function (method, actually) that “does something”, rather than one which “returns something.”
Some people, mostly those trained in languages where you are required to state these things explicitly, call the former “void functions”, and the latter, “fruitful functions”.
sorted(), on the other hand, is a Python built-in function which will take an iterable sequence and return a second sequence, namely a sorted version of the first. Fruitful.