In a nutshell, a shallow copy copies only the parent object and does not copy the sub-image.
Note: The difference between a shallow copy and a deep copy is simply that for a composite object, the so-called composite object is an object that contains other objects, such as lists, class instances. In the case of numbers, strings, and other "atomic" types, there is no copy that says that the original object's references are generated. Here's a code to demonstrate
Import copya=[[1,2],[3,4]]b=copy.copy (a) C=copy.deepcopy (a)
Now a B c is equal to [[1,2],[3,4]]
Now let's change the parent object of a.
A.append (5)
Now print the value of a B C and turn it into a
This is because both deep and shallow copies copy the parent object, which is independent of the parent object, so the value does not change.
Now let's change the sub-object of a.
A[0][0]=0
Now to print the value of a B C
A shallow copy copies only the parent object, so when A's sub-object changes, the sub-object of the shallow copy of B is changed, and the sub-object of the deep copy of C is independent, so it does not change
Deep copy and shallow copy of Python