I have a question about how Python manage deep and shallow copies.
From what I have read:
- The shallow-copy constructs a new compound object and then (to the extent possible) inserts references into it to the objects found in the original.
- The deep copy constructs a new compound object and then, recursively, inserts copies into it of the objects found in the original.
If you do:
a = list()
b = a
a.append(1)
print(b)
It will show that b = [1]. If I change b it will modify a. If I change a it will modify b, as they are both pointing to the same list... (right?)
So, If I have understood it correctly, does this means that Python manage shallow copies with lists?? Is this
b = a
a shallow copy??Do shallow/deep copies depend on the mutability (Mutable/Inmutable) of the classes?
Thank you in advance.