Python-deep copy is not always understood, just a conceptual understanding like what you said, knock out the code below and hopefully you'll understand.
1. Copy.copy a shallow copy copies only the parent object and does not copy the inner child objects of the object.
2. copy.deepcopy deep copy copy objects and their sub-objects
>>> import copy>>> l1 = [1,3,5,[' A ', ' B ', ' C ']]>>> a = l1>>> B = Copy.copy (a) # shallow copy >& gt;> C = Copy.deepcopy (a) # deep copy >>> l1.append (7) >>> l1[3].append (' d ') >>> print ' l1= ', l1l1= [1, 3, 5, [' A ', ' B ', ' C ', ' d '], 7]>>> print ' a= ', aa= [1, 3, 5, [' A ', ' B ', ' C ', ' d '], 7]>>> print ' b= ', BB = [1, 3, 5, [' A ', ' B ', ' C ', ' d ']] >>> print ' c= ', cc= [1, 3, 5, [' A ', ' B ', ' C ']] # deep copy data no change
Note: The difference between a deep copy is a nested part, a shallow copy and the elements of the nested part of the copied object are the same,
A change of the other will also change, listed above example L1 = [1,3,5,[' A ', ' B ', ' C ']], the nested part is [' A ', ' B ', ' C '], where the data changes, the shallow copy will also change.
More detailed Reference Blog http://blog.csdn.net/jerry_1126/article/details/41852591
This article is from the "Sdsca" blog, make sure to keep this source http://sdsca.blog.51cto.com/10852974/1983766
Python's deep-down copy is finally clear.