Puzzled by list-appending behavior

Uncle Ben bgreen at nycap.rr.com
Thu May 26 03:33:44 EDT 2011


On May 26, 12:46 am, Uncle Ben <bgr... at nycap.rr.com> wrote:
> In playing with lists of lists, I found the following:
>
> (In 3.1, but the same happens also in 2.7)
>
> list = [1,2,3]
> list.append ( [4,5,6] )
> x = list
> x   ->
>     [1,2,3,[4,5,6]]
> as expected.
>
> But the shortcut fails:
>
> list=[1,2,3]
> x = list.append( [4,5,6] )
> x   ->
>    nothing
>
> Can someone explain this to me?
>
> Uncle Ben

Thank you all.  It is wonderful to have this community as a resource.

Uncle Ben



More information about the Python-list mailing list