Here's 2 pieces of Python code:
t = (1, [2])
t[1] += [3]
and
t = (1, [2])
t[1].append(3)
The first piece firstly modifies the inner list t[1]
, and than throws an exception while trying to reassign value in the tuple. Though value of t
has actually changed, this behaviour is more or less understandable. But the second piece of code changes the tuple without any error/exception/whatever (as I understand, because it changes list t[1]
without reassignment).
The question is, doesn't this stuff contradict the immutability of tuples?