In Python, the assignment statement (= operator) does not copy objects, but instead, it creates a binding between the existing object and the target variable name. Thus, if you wish to create copies of an object in Python, you need to use the copy module. There are two ways to create copies for a particular object using the copy module:
- Shallow copy – It is a bit-wise copy of an object. The copied object will have an exact replica of the values contained in the original object. If any of the values are references to other objects, only the reference addresses for the same will be copied.
- Deep copy — It copies all values recursively from source to target object, meaning, it will duplicate even the objects that are referenced by the source object.