Shallow copying vs Deep copying

0 votes
What's the difference between deep copying and shallow copying? I honestly did not know there were different types of copying.
Jun 11 in Python by Varsha
62 views

1 answer to this question.

0 votes

If you have an object and you wish to copy it. There are two ways of copying it - Shallow and Deep. 

The normal copy that we generally use is called Shallow copying which basically creates a new variable and stores the reference of the copied item. It's not a clone or not the real object. Hence any change made to the copy version of an object will be reflected to the original object.

Import copy
list = [1,2,3,4]
list1 = copy.copy(list)

Deep copy, on the other hand, sends a copy of the copied version of the actual object. Hence any changes made to the copy will not be reflected in the original.

import copy
list = [1,2,3,4]
list2 = copy.deepcopy(list)
answered Jun 11 by Kyraa

Related Questions In Python

0 votes
1 answer

Copying lists in python

Assigning one list to another one simply ...READ MORE

answered Apr 30, 2018 in Python by Nietzsche's daemon
• 4,260 points
43 views
0 votes
1 answer

SKLearn NMF Vs Custom NMF

The choice of the optimizer has a ...READ MORE

answered May 9, 2018 in Python by charlie_brown
• 7,720 points
423 views
+1 vote
2 answers

Difference between append vs. extend list methods in Python

Python append() method adds an element to ...READ MORE

answered Aug 21 in Python by germyrinn
• 180 points
322 views
+2 votes
2 answers

Compiled vs Interpreted Languages

Compiled languages are written in a code ...READ MORE

answered Dec 3, 2018 in Python by allenvarna
• 520 points
362 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 413 views
+4 votes
6 answers
+7 votes
8 answers

Difference for string comparison in Python: 'is' vs. ==

If we use "==" means both variables ...READ MORE

answered Sep 3, 2018 in Python by Parul Raheja
498 views
0 votes
1 answer

df.mul vs df.rmul in Pandas

The documentation is not identical. As stated ...READ MORE

answered Jan 18 in Python by SDeb
• 13,210 points
187 views