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

John Nagle nagle at animats.com
Fri Jul 16 13:40:27 EDT 2010


On 7/13/2010 4:22 AM, Gregory Ewing wrote:
> John Nagle wrote:
>> Arguably, if a function just does a "return",
>> it should be an error to try to use its return value.
>
> It's been suggested at least once before that the
> default return value for a function should be some
> special value that raises an exception if you try
> to do anything with it except throw it away.

     Treating that case as an error would be consistent with the
way attribute access works in Python.  In Python, attempting
to access a nonexistent attribute raises an exception.  In
Javascript, that returns a null.  Javascript makes no
distinction between "null" and "nonexistent", but Python
does.

     It's un-Pythonic and inconsistent that functions which
return nothing are considered to return a None object.

				John Nagle



More information about the Python-list mailing list