append on lists

Tino Wildenhain tino at wildenhain.de
Mon Sep 15 16:44:29 EDT 2008


Armin 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.
> If d should reference the list a extended with a single list element
> you need at least two lines
> 
> a.append(7)
> d=a
> 
> and not more intuitive d = a.append(7)

Nope. Why wouln'd you just use a instead of d? And if you
want a not to be modified in place, just write: d=a+[7]

T.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20080915/306e6894/attachment-0001.bin>


More information about the Python-list mailing list