---
title: "What’s the difference between shallow copy and deep copy in Python? Give an example."  
description: "What’s the difference between shallow copy and deep copy in Python? Give an example."  
author: "Anubhav Sharma"  
published: 2025-04-21  
updated: 2025-10-30  
canonical: https://www.mindstick.com/forum/161508/what-s-the-difference-between-shallow-copy-and-deep-copy-in-python-give-an-example  
category: "python"  
tags: ["python-3.4", "python"]  
reading_time: 3 minutes  

---

# What’s the difference between shallow copy and deep copy in Python? Give an example.

What’s the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between shallow [copy and deep](https://www.mindstick.com/interview/22794/difference-between-shallow-copy-and-deep-copy) copy in Python? Give an example.

## Replies

### Reply by Mayank kumar Verma

**Shallow [copy](https://www.mindstick.com/forum/161993/explain-the-numpy-array-copy-vs-view-with-example)** ( Quick Duplication )\
A shallow copy creates a new outer object but it copies the references (memory location ) of the inner, nested object.

- **Result -** Changes made to a nested object in the copy will affect the original object and vice versa. They are not fully indipendent

**Deep copy** (full indenpendence )\
a deep copy creates a new outer object and recursively creates a new copies of all nested objects inside of it.

- **Result -** the copy is completely is separate from the origenal . Changes made to any part of the copy wii not affect the original object.

## Simple Example

Imagine `original = [[1], [2]]`.

| **Action** | **Original List** | **Shallow Copy** | **Deep Copy** |
| --- | --- | --- | --- |
| **Initial State** | `[[1], [2]]` | `[[1], [2]]` | `[[1], [2]]` |
| **Change:** `original[0][0] = 999` | `[[999], [2]]` | `[[999], [2]]` | `[[1], [2]]` |
| **Reason** | *Shallow copy shares the inner list* `[1]` *with the original, so the change is seen in both.* | *Deep copy has its own separate inner list, so it remains unchanged.* |  |

\
Use `copy.copy()` for shallow, and `copy.deepcopy()` for deep.\

### Reply by Khushi Singh

Understanding the difference between shallow and [deep](https://yourviews.mindstick.com/view/87451/a-journey-into-the-deep-dubai-s-underwater-wonderland) copy represents an essential aspect of working with nested lists or dictionaries in the [Python programming language](https://www.mindstick.com/articles/337998/how-to-improve-python-coding-skills). These two types of copying methods create duplicates of objects yet they function in completely different ways regarding nested elements. During a [shallow copy](https://www.mindstick.com/interview/33945/discuss-the-differences-between-deep-copy-and-shallow-copy-in-java-objects) operation a single new object emerges yet the original contains entire nested objects which the new object fails to duplicate. The shallow copy process duplicates only the object references but it does not duplicate those nested objects.

The original object along with its shallow copy will share identical references to their mutable types as dictionaries and lists. When using a shallow copy the modifications that occur to the nested objects present in the original object will also affect those nested objects. Deep copies generate an independent object duplicate together with independent instances for all original object nestings.

The [recursive](https://www.mindstick.com/blog/598/binary-search-using-recursion-in-java) element copy process creates a stand-alone duplicated object that disconnects it from its original version. A deep copy of data preserves the original object state since it does not apply alterations made to the nested details. The Python copy module includes two functions: copy() for shallow copying and deepcopy() for deep copying.

[Programmers](https://www.mindstick.com/articles/312357/python-programmers-need-to-focus-on-the-scope-of-a-name-for-access) must use deep copy functions when dealing with data because unintended changes in machine learning models can impact their results or behavior.

```python
import copy
original = [[1, 2], [3, 4]]
shallow = copy.copy(original)
deep = copy.deepcopy(original)
shallow[0][0] = 100
deep[1][1] = 200
print("Original:", original)   # Output: [[100, 2], [3, 4]]
print("Shallow:", shallow)     # Output: [[100, 2], [3, 4]]
print("Deep:", deep)           # Output: [[1, 2], [3, 200]]
```

A shallow copy will maintain identical nested elements whereas deep copy produces independent duplicate versions.


---

Original Source: https://www.mindstick.com/forum/161508/what-s-the-difference-between-shallow-copy-and-deep-copy-in-python-give-an-example

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
