This is more of a curiosity
Say I have the following code
>>> my_immutable = (1, 2)
>>> my_immutable[0] += 1
TypeError: 'tuple' object does not support item assignment
This is expected, because unlike C, Python does not modify the underlying int, but rather creates a new one (observed in the code below)
>>> x = 1
>>> id(x)
33156200
>>> x += 1
>>> id(x)
33156176
If I want to modify the underlying integer in the tuple, I can hackly do something like
>>> hacked_immutable = ([1], [2])
>>> hacked_immutable[0][0] += 1
>>> hacked_immutable
([2], [2])
My question is: is there a nicer way of doing it (ideally performant and ideally already in the standard library)? Some wrapper class around int maybe?