Exmaple 1
a = [1,[2,3],[4]]
b = a[1]
print(b)
Output:
[2, 3]
b[1] = 88
print(a)
print(b)
Output:
[1, [2, 88], [4]]
[2, 88]
Example 2
a = [1,[2,3],[4]]
b = a[0]
print(b)
Output:
1
b = 88
print(a)
print(b)
Output:
[1, [2, 3], [4]]
88
Example 3
a = [1,[2,3],[4]]
b = a[2]
print(b)
Output:
[4]
b = 88
print(a)
print(b)
Output:
[1, [2, 3], [4]]
88
Example 4
a = [1,[2,3],[4]]
b = a[2]
print(b)
Output:
[4]
b[0] = 88
print(a)
print(b)
Output:
[1, [2, 3], [88]]
[88]
So when a is a list of list, and b is assigned a list value then a change of value in b changes the original list. However, when b is assigned just a regular value then a change in value in b does not change the original list. Then in the last two examples we see that even if b is a list but if we assign it a value then it doesnt change the original list. Why is this the case? What types of structures have this property where the assignment in some secondary variable changes the original variable?