When I do:
a = [7,3,4]
b = a
b[0] = 10
b[0]
is of course set to 10
, but a[0]
is also set to 10
. Why is this?
When I do:
a = [7,3,4]
b = a
b[0] = 10
b[0]
is of course set to 10
, but a[0]
is also set to 10
. Why is this?
b = a
This makes b
and a
reference to the same list object. If you want b
to reference to a new list object that is a copy of a
, try:
b = a[:]