[Tutor] assignment question
steve at alchemy.com
Mon Nov 12 05:50:30 CET 2007
Ryan Hughes wrote:
> Why does the following not return [1,2,3,4] ?
>>>> x = [1,2,3].append(4)
>>>> print x
because the append() method doesn't return a copy of the list object; it
just modifies the list itself.
so your code constructs a list object with 3 elements, appends a fourth
element to it, and throws that list object away, keeping only the return
value of append().
More information about the Tutor