Python Deep copy and shallow copy : This only happens if the container contains a variable data container type
A shallow copy may cause the value after the copy to be modified , Will change the original value
>>> a={"name":"sc","score":[80,90,100]}
>>> b=a.copy()
>>> a
{'name': 'sc', 'score': [80, 90, 100]}
>>> b
{'name': 'sc', 'score': [80, 90, 100]}
>>> b["score"].append(110)
>>> a
{'name': 'sc', 'score': [80, 90, 100, 110]}
>>> b
{'name': 'sc', 'score': [80, 90, 100, 110]}
>>> id(a["score"])
140622729707336
>>> id(b["score"])
140622729707336
>>> id(b)
140622729725560
>>> id(a)
140622729724120
Shallow copy only copies the address of the first layer object ( quote )
Deep copy is to copy the data of each layer ( Use copy Modular deepcopy function )
>>> import copy
>>> b=copy.deepcopy(a) Make a deep copy
>>> a
{'name': 'sc', 'score': [80, 90, 100, 110]}
>>> b
{'name': 'sc', 'score': [80, 90, 100, 110]}
>>> id(a["score"])
140622729707336
>>> id(b["score"])
140622722255816
>>> id(b["name"]) “sc” String resident entered , therefore id identical
140622729721424
>>> id(a["name"])
140622729721424
>>> b["score"].append(120)
>>> b
{'name': 'sc', 'score': [80, 90, 100, 110, 120]}
>>> a
{'name': 'sc', 'score': [80, 90, 100, 110]}