-
Direct assignment:It is essentially a reference (alias) to the object.
-
Shallow copy:Copies the parent object, but does not copy the internal child objects of the object.
-
Deep copy:The deepcopy method of the copy module fully copies the parent object and its child objects.
Dictionary Shallow Copy Example
Example
Deep copy requires importing the copy module:
Example
Analysis
1、b = a: Assignment by reference — both a and b point to the same object.

2、b = a.copy():Shallow copy — a and b are independent objects, but their child objects still point to the same object (they are references).

b = copy.deepcopy(a):Deep copy — a and b fully copy the parent object and its child objects, and the two are completely independent.

More Examples
The following examples use copy.copy (shallow copy) and copy.deepcopy (deep copy) from the copy module:
Example
The output of the above example is:
('a = ', [1, 2, 3, 4, ['a', 'b', 'c'], 5])
('b = ', [1, 2, 3, 4, ['a', 'b', 'c'], 5])
('c = ', [1, 2, 3, 4, ['a', 'b', 'c']])
('d = ', [1, 2, 3, 4, ['a', 'b']])