as we know that tuple is immutable but if a tuple holds a list inside,can we append an respective list?
t=(1,2,3,"hi",[2,3,4],True)
t[4].append(7)
print(t)
output
(1,2,3,"hi",[2,3,4,7],True)
as we know that tuple is immutable but if a tuple holds a list inside,can we append an respective list?
t=(1,2,3,"hi",[2,3,4],True)
t[4].append(7)
print(t)
output
(1,2,3,"hi",[2,3,4,7],True)
Because under the hood python is not holding the array itself, but its reference. So as long as the reference doesn't change it's ok!!
So imagine the memory addresses
0x00 = 1
0x01 = 2
0x02 = 3
0x03 = "hi"
0x04 = 0x10
0x05 = True
0x10 = 2
0x11 = 3
0x12 = 4
If you add more elements to the array, the values between 0x00 and 0x05 won't change, and that is the immutable behavior on python