What is a deep copy operation in Python?

31.08.2016

Philip Sahli

What is a deep copy operation in Python?

A deep copy constructs a new compound object and then, recursively, inserts copies into it of the objects found in the original.

Assignment statements in Python do not copy objects, they create bindings between a target and an object. For collections that are mutable or contain mutable items, a copy is sometimes needed so one can change one copy without changing the other. This module provides generic shallow and deep copy operations (explained below).