Tuples

Dave Hansen iddw at hotmail.com
Thu Dec 15 12:29:23 EST 2005


On 15 Dec 2005 09:19:37 -0800 in comp.lang.python, "Tuvas"
<tuvas21 at gmail.com> wrote:

>Let's say I make a program something like follows:
>
>x=[]
>x.append([1,2,3])
>x.append([4,5,6])
>print x
>print x[0]
>print x[0][1]
>x[0][1]=5
>
>Okay, everything works here as expected except the last line. Why won't
>this work? Thanks for the help!

Perhaps because you're not expecting the right thing?  Here's what I
get:

>>> x = []
>>> x.append([1,2,3])
>>> x.append([4,5,6])
>>> print x, x[0], x[0][1]
[[1, 2, 3], [4, 5, 6]] [1, 2, 3] 2
>>> x[0][1]=5
>>> print x
[[1, 5, 3], [4, 5, 6]]
>>>

Which is what i would expect.  Regards,

                                        -=Dave

-- 
Change is inevitable, progress is not.



More information about the Python-list mailing list