shallow and deep copy code example

Example 1: example of a deep copy in python

# deep copy example in python
import copy

old_list = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]
new_list = copy.deepcopy(old_list)

old_list[1][0] = 'BB'

print("Old list:", old_list)
print("New list:", new_list)

# OUTPUT
Old list: [[1, 1, 1], ['BB', 2, 2], [3, 3, 3]]
New list: [[1, 1, 1], [2, 2, 2], [3, 3, 3]]

Example 2: shallow clone

How to Execute Git Shallow Clone
Provide an argument of -- depth 1 to the git clone command to copy only the latest revision of a repo:

git clone -–depth [depth] [remote-url]
 

You can also use git shallow clone to access a single branch:

git clone [remote-url] --branch [name] --single-branch [folder]
 

With git shallow clone you get fewer files. And as a result, they clone faster. Builds and feedback can be delivered quicker.

Example 3: shallow copy vs deep copy js

/*

Search Results
Featured snippet from the web
A deep copy means that all of the values of the new variable
are copied and disconnected from the original variable. 
A shallow copy means that certain (sub-)values are still connected
to the original variable. To really understand copying,
you have to get into how JavaScript stores values


/*

Tags:

Misc Example