Why doesn't python's list append() method return the list itself?

John Nagle nagle at animats.com
Mon Jul 12 15:46:08 EDT 2010


On 7/11/2010 5:24 PM, Steven D'Aprano wrote:
> On Sun, 11 Jul 2010 08:59:06 -0700, dhruvbird wrote:
>
>> Why doesn't python's list append() method return the list itself? For
>> that matter, even the reverse() and sort() methods? I found this link
>> (http://code.google.com/edu/languages/google-python- class/lists.html)
>> which suggests that this is done to make sure that the programmer
>> understands that the list is being modified in place, but that rules out
>> constructs like:
>> ([1,2,3,4].reverse()+[[]]).reverse()
>
> Yes. So what? Where's the problem?
>
> List methods work in place.
...
> Not everything needs to be a one-liner.

    It's interesting that all Python functions are considered to
return a value.  Arguably, if a function just does a "return",
it should be an error to try to use its return value.

    Some languages have a very functional orientation, and
everything is considered to return some value, even
control structures. LISP is like that.  But Python isn't
one of those languages.

				John Nagle




More information about the Python-list mailing list