is there any way to keep list a unmodified by changing list b?
a = [1,2,3]
b = a
print(a)
print(b)
b[0]=100
print(a)
print(b)
Output:
[1, 2, 3]
[1, 2, 3]
[100, 2, 3]
[100, 2, 3]
is there any way to keep list a unmodified by changing list b?
a = [1,2,3]
b = a
print(a)
print(b)
b[0]=100
print(a)
print(b)
Output:
[1, 2, 3]
[1, 2, 3]
[100, 2, 3]
[100, 2, 3]
Yes, make a copy of list a:
a = [1, 2, 3]
b = a.copy()
...
By copying it, you get a new list with identical contents.