-1

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]
1
  • just assign a new list to b
    – Netwave
    May 17, 2018 at 11:58

1 Answer 1

0

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.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.