Assignment, Shallow Copy (Copy) and Deep Copy
- Assignment: Just add one more reference to the origin object
- Shallow Copy: Or just Copy, which will just copy top level object, but will not copy sub-level object (add one more reference for sub-level object)
- Deep Copy: Completely copy the whole object
Example using dictionary
1 | >>>import copy |
Explanation
b=a: assignment,aandbwill point to the same objectb=a.copy(): shallow copy,aandbare independent object, however, their sub-objects still point to the same object.b=a.deepcopy(): deep copy,aandbare totally independent object, at any level.


