Skip to main content
Loading page…
Python Mastery
Chapter 13
Lesson 3 of 4
Copying: Shallow vs Deep
Contents
Notes
Tutor
Concept
Three Levels of 'Copying'
Loading activity…
Previous
1 / 10
Continue
Contents
Notes
Discussion
Tutor
26 min
10 activities
0 of 10 done
In this lesson
1
Three Levels of 'Copying'
2
Memory Diagram: Assignment vs Shallow vs Deep
3
When Shallow Copy Is Enough — and When It Isn't
4
Custom __copy__ and __deepcopy__
5
Shallow vs Deep: Predict & Verify
6
Order the Copying Operations from Least to Most Isolated
7
Shallow Copy Trap
8
Deep Copy a Tree Structure
9
Performance: Deep Copy Is Expensive
10
Match Copying Method to Use Case
Objectives
Distinguish assignment (no copy) from shallow copy from deep copy
Predict which parts of a nested structure are shared after a shallow copy
Use the copy module correctly, including copy.copy() and copy.deepcopy()
Implement __copy__ and __deepcopy__ for custom classes
Choose the right copying strategy for a given situation
Chapter 13 · The Python Data Model & Memory
Objects, Identity & References
Mutability, Hashability & Shared State
Copying: Shallow vs Deep
Memory, Reference Counting & __slots__
Previous: Mutability, Hashability & Shared State
Next: Memory, Reference Counting & __slots__