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, 2019 in Python by Varsha

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, 2019 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
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,780 points
+1 vote
3 answers

Difference between append vs. extend list methods in Python

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

answered Aug 21, 2019 in Python by germyrinn
• 240 points
+3 votes
2 answers

Compiled vs Interpreted Languages

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

answered Dec 3, 2018 in Python by allenvarna
• 540 points
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,400 views
0 votes
0 answers
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
+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
0 votes
1 answer

df.mul vs df.rmul in Pandas

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

answered Jan 18, 2019 in Python by SDeb
• 13,300 points