---
title: "What is the difference between a shallow copy and a deep copy?"  
description: "What is the difference between a shallow copy and a deep copy?"  
author: "Ravi Vishwakarma"  
published: 2025-04-22  
updated: 2025-06-02  
canonical: https://www.mindstick.com/forum/161521/what-is-the-difference-between-a-shallow-copy-and-a-deep-copy  
category: "python"  
tags: ["python-3.4", "python"]  
reading_time: 2 minutes  

---

# What is the difference between a shallow copy and a deep copy?

What is the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between a [shallow copy](https://www.mindstick.com/interview/33945/discuss-the-differences-between-deep-copy-and-shallow-copy-in-java-objects) and a [deep](https://yourviews.mindstick.com/view/87451/a-journey-into-the-deep-dubai-s-underwater-wonderland) copy?

## Replies

### Reply by Ravi Vishwakarma

### Shallow Copy

- Creates a new object, but **the contents (elements or references inside the object) are not copied recursively**.
- The new object’s fields reference the **same nested objects** as the original.
- So changes to nested mutable objects inside either the original or the [copy](https://www.mindstick.com/forum/161993/explain-the-numpy-array-copy-vs-view-with-example) **will affect both**.

## Example:

```python
import copy

original = [1, 2, [3, 4]]
shallow = copy.copy(original)

shallow[2][0] = 'changed'
print(original)  # Output: [1, 2, ['changed', 4]]
```

Notice how modifying the nested list inside `shallow` also changed it in `original`.

### Deep Copy

- Creates a new object **and recursively copies all objects found inside it**.
- The copy is **completely independent** of the original.
- Changes to any part of the copy won’t affect the original.

## Example:

```python
import copy

original = [1, 2, [3, 4]]
deep = copy.deepcopy(original)

deep[2][0] = 'changed'
print(original)  # Output: [1, 2, [3, 4]]
```

Here, the nested list inside `deep` is a completely separate copy, so modifying it does not change `original`.

### Summary:

| Feature | Shallow Copy | Deep Copy |
| --- | --- | --- |
| Copies object | Yes | Yes |
| Copies nested objects | No (references shared) | Yes (recursively copies nested objs) |
| Changes to nested mutable objects | Reflect in both copies | Independent |
| Use case | When nested objects are immutable or shared intentionally | When you need fully independent copy |


---

Original Source: https://www.mindstick.com/forum/161521/what-is-the-difference-between-a-shallow-copy-and-a-deep-copy

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
