In the list, you want to copy a list, you can use the copy () function, in the list, the copy () function is the same as the slice [:] function
a=[0,1,[0,1]]
B=a.copy ()
c=a[:]
-----Print B,c-----
b=[0,1,[0,1]]
c=[0,1,[0,1]]
Copy.copy () also has the same function in copy module, but there is a function in the copy module that is similar to copy.copy (), but functions differently, that is copy.deepcopy ()
This is the protagonist of today's ' Shallow copy copy.copy () ' and ' deep copy copy.deepcopy () '
The difference between the copy module and the copy () function in the list is first shown by a single graph.
Copy () in the visible list of this graph is not only the same as the [:] Copy.copy () function
But the two functions in the Copy module are missing.
First look at the principle of ' shallow copy copy.copy () '
The Python visualization process shows that in ' shallow copy ', B does not store a small list in the list to a new address, but rather a common address with a, so when a small list of values changes, B is the same.
Again, the ' deep copy copy.deepcopy () ' principle
As the graph shows, ' deep copy ', B stores a small list of oranges in a new address, regardless of the value of A's small list, but does not affect the small list of B.
Thanks for reading
Or a student, in the text is likely to appear wrong ideas or terminology, please senior criticism and guidance, thank you!
[PYTHON] Depth resolution copy.copy () and Copy.deepcopy ()