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
13 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
27 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,710 points
250 views
0 votes
1 answer

Difference between append vs. extend list methods in Python

append: Appends object at end. x = [1, ...READ MORE

answered Jun 4, 2018 in Python by ariaholic
• 7,320 points
126 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
187 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
63 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
377 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
• 11,020 points
71 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.