append on lists

Grant Edwards invalid at invalid
Mon Sep 15 22:40:50 CEST 2008

On 2008-09-15, Armin <a at> wrote:

>> Because .append() mutates 'a' and appends the item in-place rather
>> than creating and returning a new list with the item appended, and
>> it's good Python style for mutating methods to have no return value
>> (since all functions must have some return value, Python uses None
>> when the function doesn't explicitly return anything).
> Yes, but this is very unconvenient.

Aw, admit it -- it's not _that_ inconvenient.

> If d should reference the list a extended with a single list
> element you need at least two lines
> a.append(7)
> d=a

With that usage it's obvious that a is mutated, and now both
"a" and "d" are bound to the same extended list.

> and not more intuitive d = a.append(7)

Becase that usage implies (at least to many of us) that "a" is
unchanged, and that "d" is now bound to a different object than

Grant Edwards                   grante             Yow! Where's th' DAFFY
                                  at               DUCK EXHIBIT??

More information about the Python-list mailing list