tuple immutable or mutable
A tuple could be mutable. when a list is contained within a tuple, it creates what is often referred to as a "tuple of references to lists". This means that the elements of the tuple are references to the lists themselves, not copies of the lists.
It will be demonstrated here that a tuple can have different behaviors.
t1 = (1,[2,3],[4,5]) print(type(t1)) # <class 'tuple'>
Now, let's append or change some value inside the tuple
t1 = (1,[2,3],[5,6])
print(type(t1))
# let's append or change some value inside the tuple
t1[1].append(4)
print(t1)
# (1, [2, 3, 4], [5, 6])
"tuple of references to lists" means that the tuple contains references to the lists, and any modifications to the lists will be reflected in the tuple. That means a tuple could be mutable
Comments
Post a Comment