Hello,

This is just because you are changing the value of b and in foo there is a
reference of b.

while in
>>> foo = (1,[2,3,4])
>>> foo[1] += [6]
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> foo
(1, [2, 3, 4, 6])
>>>
it is changing the value in List but after that python has realized that the
error .

On Fri, Apr 1, 2011 at 6:54 PM, Roshan Mathews <rmath...@gmail.com> wrote:

> On Fri, Apr 1, 2011 at 18:44, Hussain Bohra <hussainbohra...@yahoo.com>
> wrote:
> > Atleast on changing list, you gets an exception.
> >
> > On updating dictionary living inside tuple wont throw an exception as
> well.
> >
> I thought the surprising part was that it threw an exception, not that
> it updated the list.  Even more surprising was that it threw the
> exception and updated the list too.
>
> >>> a, b = 1, [2, 3, 4]
> >>> foo = (a, b)
> >>> b += [5]
> >>> foo
> (1, [2, 3, 4, 5])
> >>>
>
>
>
> --
> http://about.me/rosh
> _______________________________________________
> BangPypers mailing list
> BangPypers@python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>



-- 
----------------------------
Kind regards

Ruchir Shukla

Phone: +91 9099020687
ruchiryshu...@gmail.com; Ruchir Shukla <http://ruchir-shukla.blogspot.com/>
_______________________________________________
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers

Reply via email to