Tuples and immutability

Chris Angelico rosuav at gmail.com
Fri Feb 28 09:43:55 EST 2014


On Sat, Mar 1, 2014 at 1:41 AM, Joshua Landau <joshua at landau.ws> wrote:
> Would it be better to add a check here, such that if this gets raised
> to the top-level it includes a warning ("Addition was inplace;
> variable probably mutated despite assignment failure")?

That'd require figuring out whether or not the variable was actually
mutated, and that's pretty hard to work out. So there's a FAQ entry,
which Zachary already posted:

http://docs.python.org/3/faq/programming.html#why-does-a-tuple-i-item-raise-an-exception-when-the-addition-works

Also, we just answer this question every now and then :) Presumably
more often on -tutor than here.

ChrisA



More information about the Python-list mailing list