list.extend([]) Question

Jack Diederich jackdied at
Sat Feb 6 00:43:13 CET 2010

On Fri, Feb 5, 2010 at 11:31 AM, Gerald Britton
<gerald.britton at> wrote:
> I think it's because when you do ['a'].extend([]) or whatever, the
> result is whatever the method "extend" returns.  But "extend" has no
> return value, hence you will see None if you do this interactively.

That sums it up.  In Python the convention is to raise an exception on
error, return a new value in the case where a new value is created,
and - as in this case - to return None for modification of an existing
value.  Returning "None" is vexing if you are used to another language
that has a different convention but is expected for well behaved
python libraries.

So yeah, Python does it that way because the intent is to loudly and
regularly announce that something was modified or to loudly and
regularly announce that something new was /not/ created.  It's a
boring story with no whiz-bang feature behind it, but I like that the
language behaves that way for exactly that reason.


More information about the Python-list mailing list