I was just toying around in the interpreter and ran across something that I do not understand. When I create a tuple with a list as one the elements and then try to update that list, something strange happens. For example, when I run this:
tup = (1,2,3,[4,5])
tup[3] += [6]
I get:
TypeError: 'tuple' object does not support item assignment
Which is exactly what I expected. However then when I reference the tuple again, I get:
>>> tup
(1, 2, 3, [4, 5, 6])
So the list was in fact updated even though python threw an exception. How does that work? I can't imagine a scenario where I would actually want to do something like this, but I still would like to understand what is going on. Thank you.