import copy lst = [1, 2, 3, 4] a = lst # Ref copy b = lst.copy() # Shallow copy a[0] = 11 print(id(lst)) print("Ref copy: ", lst) print("variable copy", b) print(id(a)) print(id(b)) c = copy.deepcopy(lst) # Deep copy? print(id(c)) print(c)
18844328 Ref copy: [11, 2, 3, 4] variable copy [1, 2, 3, 4] 18844328 16001080 18845600 [11, 2, 3, 4]