0

I have two lists A and B when i change A it change also at B how i prevent this?

A = [1,2,3,4,5]
B = A
A.append(6)

print(A)
print(B)

thank's for the help.

1 Answers1

0

You have one list, and two variables pointing to it.

To make B point to a copy of A, you can use B = list(A).

Snild Dolkow
  • 6,669
  • 3
  • 20
  • 32