The statement in the linked answer is broader than it should be. Implicit copies are rare in Python, and in the cases where they happen, it is arguable whether Python is performing the implicit copy, but they happen.
What is definitely true is that the default rules of name assignment do not involve a copy. By default,
a = b
will not copy the object being assigned to a
. This default can be overridden by a custom local namespace object, which can happen when using exec
or a metaclass with a __prepare__
method, but doing so is extremely rare.
As for cases where implicit copies do happen, the first that comes to mind is that the multiprocessing
standard library module performs implicit copies all over the place, which is one of the reasons that multiprocessing
causes a lot of confusion. Assignments other than name assignment may also involve copies; a.b = c
, a[b] = c
, and a[b:c] = d
may all involve copies, depending on what a
is. a[b:c] = d
is particularly likely to involve copying d
's data, although it will usually not involve producing an object that is a copy of d
.