AI engineering glossary · Python core

What is shallow copy?

Shallow copy: A copy of a container that duplicates the outer object but keeps references to the same inner objects. Changing a nested mutable item through one copy therefore also changes it in the other. Made with copy.copy(), list.copy() or slicing.

Level: intermediateTopic: Python core

Shallow copy: an example

a = [[1], [2]]; b = a.copy(); b[0].append(9) also changes a[0], which becomes [1, 9].

Related terms

More Python core terms

Where you learn it

Shallow copy is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.