Deep Copy and Shallow Copy in Python Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In Python, assignment statements create references to the same object rather than copying it. Python provides the copy module to create actual copies which offer functions for shallow (copy.copy()) and deep (copy. deepcopy ()) copies. In this article, we will explore the main difference between Deep Copy and Shallow Copy. Deep copy in PythonA deep copy creates a new compound object before inserting copies of the items found in the original into it in a recursive manner. It will first construct a new collection object and then recursively populate it with copies of the child objects found in the original. It means that any changes made to a copy of the object do not reflect in the original object. Syntax of Python Deepcopycopy.deepcopy()Example: Python import copy a = [[1, 2, 3], [4, 5, 6]] # Creating a deep copy of the nested list 'a' b = copy.deepcopy(a) # Modifying an element in the deep-copied list b[0][0] = 99 print(b) Output[[99, 2, 3], [4, 5, 6]] Explanation:copy.deepcopy() method creates a completely independent copy of the original object, including all nested elements. Changes made to deep_copied do not affect the original list a.nested elements of the original list a are recursively duplicated to ensure that even deeply nested objects are entirely independent in the copied list.Shallow copy in PythonA shallow copy creates a new object but retains references to the objects contained within the original. It only copies the top-level structure without duplicating nested elements.Changes made to a copy of an object do reflect in the original object. In python, this is implemented using the "copy.copy()" function. Syntax of Python Shallowcopycopy.copy()Example: Python import copy a = [[1, 2, 3], [4, 5, 6]] # Creating a shallow copy of the nested list 'original' b = copy.copy(a) # Modifying an element in the shallow-copied list b[0][0] = 99 # Printing the original and shallow-copied lists print(b) Output[[99, 2, 3], [4, 5, 6]] Explanation:A shallow copy only copies the outer structure, retaining references to the nested objects. In this case, the inner lists are shared between original and shallow_copied.As a result, changes to the nested elements in shallow_copied (e.g., modifying shallow_copied[0][0]) are also reflected in original. copy in Python (Deep Copy and Shallow Copy) Comment More info K kartik Follow Improve Article Tags : Python Explore Python FundamentalsPython Introduction 3 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 5 min read Python Keywords 2 min read Python Data Types 7 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 6 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 12 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 6 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 7 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 3 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like