Thanks for the response! I’m still a little confused tho. If extend works why doesn’t the += work by default? Why do I have to put it in a holder to get the += to work?
When you do x += y, you’re asking the object x to do an augmented addition, and then whatever it gives back is assigned back to x. In the case of a tuple, assignment is illegal, but before that, the effect of += on a list has already happened - it’s the same as calling extend. These two are broadly equivalent:
my_tuple[0] += [3, 4]
_temp = my_tuple[0]
_temp.extend([3, 4])
my_tuple[0] = _temp
# Or if you prefer:
my_tuple[0] = my_tuple[0].__iadd__([3, 4])
Basically, a list’s += operator is “do an extend, then return self”, and the assignment still happens. (In contrast, an integer’s += operation is “return a new integer which is the sum of myself and the other”, with no change to the original object, so the assignment is everything.)
The behaviour isn’t intentional in the sense that the confusing “exception even though the operation seemingly succeeded” is the goal. But it is intentional in the sense that we designed augmented assignments to be assignments, and assignments to a tuple item fail.