Python deep copy and shallow copy difference

Variable Types

The list, dict other types, changing the value in the container, vessel address unchanged.

Immutable type

The tuple string, change the value in principle. If you want to change the value of an object, the object is to change the address pointed to

Shallow copy

For variable objects, opening up new memory storage container object, but does not open up a new space to store the value of the container, the value of the object inside the container is still pointing to the original address. Ie only copy of the object the outer layer

Value of the object will be copied immutable object to copy

Deep copy

For variable objects, both opening up new memory storage container object, but also open up new space to store the value of the container. That is, both copies of the container object, copy the value of the object but also objects inside of the container

Value of the object will be copied immutable object to copy

Below is a map of my own painting can be more intuitive understanding of Python in deep copy and shallow copy of difference

 

 

Guess you like

Origin www.cnblogs.com/mumuxin-gv/p/11908385.html