if you do b = a,
you didn’t copy the list referenced by
a. You just created a new tag b and attached it to the list pointed by a. Like in the picture below:
If you modify
a, you also modify b, since they point to the same list.
Now we want to copy the list referenced by
a. We need to create a new list to attach b to it.
b = a[:]
b = a.copy()
No comments:
Post a Comment