One, the depth of the copy
A deep copy refers to the copy () and Deepcopy () methods under the Copy module.
1. Shallow copy
Example:
>>>ImportCopy>>> A ='Hello Word'>>> B = {1:'Gome', 2:'Ahaii', 3:[1,2,3,4]}>>> A1 =Copy.copy (a)>>> B1 =copy.copy (b)>>>PrintID (a)140458175739296>>>PrintID (A1)140458175739296>>>PrintID (b)140458175695680>>>PrintID (B1)140458175749208>>>PrintID (b[3])140458175609096>>>PrintID (b1[3])140458175609096>>>PrintID (b[3][0])41361752>>>PrintID (b1[3][0])41361752
When a shallow copy occurs, the memory address of the variable does not change.
2. Deep copy
Example 1:
Import Copy ' Hello Word ' Print ID (a)140069292463520>>> a1 = copy.deepcopy (a)print ID (A1) 140069292463520
For a string or integer, a deep copy has the same effect as a shallow copy, and its memory address does not change.
Example 2:
>>>ImportCopy>>> B = {1:'Hello Word', 2:'Ahaii', 3:[1,2,3,4]}>>> B1 =copy.deepcopy (b)>>>PrintID (b)140442326100800>>>PrintID (B1)140442326156184>>>PrintID (b[3])140442326014216>>>PrintID (b1[3])140442326097288>>>PrintID (b[3][0])32555352>>>PrintID (b1[3][0])32555352
Deep copy, except for the most inner data (string or number), other data will be recreated, memory address changes.
The dynamic parameters of the function
adjourned
Python Quest Path 2---depth copy, function