0

I've been playing around with lists and I've been having trouble with code like this:

a = [1,2,3,4]
b = a
b.append(5)
print(a)
print(b)

Output:

[1,2,3,4,5]
[1,2,3,4,5]

Why is b.append appending to list a as well? Is there a way to prevent this?

0 Answers0