append on lists
hniksic at xemacs.org
Tue Sep 16 10:48:42 CEST 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