Is the behaviour of Python’s list += iterable documented anywhere?

From Guido van Rossum:

It works the same way as .extend() except that it also returns self. I
can’t find docs explaining this. 🙁

Here is the relevant source code taken from listobject.c:

list_inplace_concat(PyListObject *self, PyObject *other)
{
     PyObject *result;

     result = listextend(self, other);
     if (result == NULL)
         return result;
     Py_DECREF(result);
     Py_INCREF(self);
     return (PyObject *)self;
}

I’ve raised a bug report to have the documentation fixed: http://bugs.python.org/issue16701

Leave a Comment