Python Data Types: Copying objects

Shallow copy

  • used when a new instance type gets created and it keeps the values that are copied in the new instance.
  • used to copy the reference pointers just like it copies the values.
  • allows faster execution of the program and it depends on the size of the data that is used.

Deep copy

  • used to store the values that are already copied.
  • doesn’t copy the reference pointers to the objects, it makes the reference to an object and the new object that is pointed by some other object gets stored.
  • makes execution of the program slower due to making certain copies for each object that is been called.

Python Data Types: Copying objects — Structure map

Clickable & Draggable!

Python Data Types: Copying objects — Related pages: