a = [1,2,3,4,5]
b = a
a.remove(a[0])
print(b)
The values of a
have been stored into b
before a.remove
was called. I don't get how this works.
a = [1,2,3,4,5]
b = a
a.remove(a[0])
print(b)
The values of a
have been stored into b
before a.remove
was called. I don't get how this works.
because the b
list is just a reference to a
list and not a copy by value. if you want to have a copy of a
list, try this:
a = [1, 2, 3, 4, 5]
b = a[:]
a.remove(a[0])
print(b)