What is the difference between the term Shallow copy and Deep?

A deep copy copies an object into another. This means that if you make a change to a copy of an object, it won’t affect the original object. In Python, we use the function deepcopy() for this, and we import the module copy.

  1. import copy

  2. b=copy.deepcopy(a)

A shallow copy, however, copies one object’s reference to another. So, if we make a change in the copy, it will affect the original object. For this, we have the function copy().

  • b=copy.copy(a)

Sorry for the incorrect format of code.
Here is the revised answer-

A deep copy copies an object into another. This means that if you make a change to a copy of an object, it won’t affect the original object. In Python, we use the function deepcopy() for this, and we import the module copy.

>>>import copy

>>>b=copy.deepcopy(a)

A shallow copy, however, copies one object’s reference to another. So, if we make a change in the copy, it will affect the original object. For this, we have the function copy().

>>>b=copy.copy(a)

A SHALLOW copy means constucting a new collection object and then populating it wit references to the child objects found in original or A shallow copy creates a new object which stores the reference of the original elements.

A DEEP copy makes the copying process recursive.it means A deep copy creates a new object and recursively adds the copies of nested objects present in the original elements.It first constucting a new collection object and then recursively populating it with copies of the child objects found in the original.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.