append on lists

Hrvoje Niksic hniksic at xemacs.org
Tue Sep 16 04:48:42 EDT 2008


"Chris Rebert" <clp at rebertia.com> writes:

>>  c = [9,10]
>>  [1,2,3,4,7].append(c) -> Is this a valid expression?
>
> Literally, no, because you can't call methods on literals.

This is in fact not true.  [1,2,3,4,7].append([9, 10]) is a perfectly
valid expression, only it doesn't do much (that you can observe).

The canonical response (no doubt already quoted in this thread) is
that returning the list from append would confuse the hell out of
people who expect a copy of the list, such as:

a = [1, 2, 3]
b = a.append(4)
# if the above "worked" in the sense that b == [1, 2, 3, 4], I for one
# would expect a to remain unchanged



More information about the Python-list mailing list