If list.sort
would return a copy of itself, programmers not knowing that the sorting happens in place would happily write code like this:
def foo(my_list):
return my_list.sort()
Since this works, they might be under the impression that the sorting happens only on a copy of the list, until some day they realise that they’ve been introducing subtle bugs into their code all along.
By denying this code to work in the first place, that ambiguity and a source of bugs is removed from the language entirely.
2
solved Why in principle an in-place-modifying method should return None [closed]