Deep vs Shallow Copies in Python

Joseph Peart
Joseph Peart 9 Lessons 44m advanced python

When working with Python objects, you’ll often need to make copies rather than modify the originals. In this video course, you’ll explore various ways to copy objects in Python, including using the built-in copy module. You’ll also learn the key differences between shallow and deep copies, with practical examples so you can safely duplicate objects in your own code.

By the end of this video course, you’ll understand that:

  • Shallow copying creates a new object but references the same nested objects, leading to shared changes.
  • Deep copying recursively duplicates all objects, ensuring full independence from the original.
  • Python’s copy module provides the copy() function for shallow copies and deepcopy() for deep copies.
  • Custom classes can implement .__copy__() and .__deepcopy__() for specific copying behavior.
  • Assignment in Python binds variable names to objects without copying, unlike some lower-level languages.

What’s Included:

  • 9 Lessons
  • Video Subtitles and Full Transcripts
  • 2 Downloadable Resources
  • Accompanying Text-Based Tutorial
  • Interactive Quiz to Check Your Progress
  • Q&A With Python Experts: Ask a Question
  • Certificate of Completion

Downloadable Resources:

Related Learning Paths:

About Joseph Peart

Joseph is a software developer, data geek, bootcamp instructor, and board game enthusiast. He lives in Canada with his wife and cats. He loves learning new things, teaching those things to other people, and talking about himself in the third person.

» More about Joseph

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

← Browse All Courses