Breaking reference to object in Python

1.5k views Asked by At

If I write the following code:

a = []
b = a
b.append(2)

Then a = [2]. Is there a way I can break the reference between b and a, so that even if I modify b, a will not be modified?

1

There are 1 answers

0
TobiasR. On

You can, if you copy its content with

b=a[:]