Tuples write protectedness

If tuples are immutable, then how is t=3*t working…it is also changing its content?(The write -protect feature isn’t followed then?)

Hey @nikhil_sarda, tupples are immutable, means no change can be made on same location,
Suppose t = (1,2,3), it is stored at 12K address, now you can’t do t[0] = 5, it will give you error.
But when you do t = 3t, than a new tuple is formed by 3t having its elements three times that of t, and now it is stored in variable t. Now address(t) != 12K . it will be something elsel.

you can check it your self ,by adding hex(id(t)) # this prints memory address.
Add this both below and after the operation.

HOpet this resolved your doubt.
Plz mark it as resolved in my doubts section. :blush:

1 Like