+ 1

Copy question in Python

Some notes on copy problems Case 1 a=b If a&b are int or str it doesn’t matter If a&b are list, DataFrame or similar objects, they would refer to the same object all the time Any change in a would change b, vice versa Case 2 b=a.copy() This is a shallow copy a&b are different objects, but they share elements Adding elements to b won’t change a But any change in elements in a would change b, vice versa Case 3 Create a deep copy b=a.copy(deep=True) #as in Pandas a&b are different objects. They don’t share elements. Any change on a won’t change b

7th Apr 2019, 10:38 AM
Jasmine
Jasmine - avatar
1 Answer
+ 4
Basically, these are all the behavior of python programming language regarding different types of cases in copying list. I think you need an explanation about that. There are some articles present on the internet which you can check them out. Here is one for you:) https://www-geeksforgeeks-org.cdn.ampproject.org/v/s/www.geeksforgeeks.org/python-cloning-copying-list/amp/?amp_js_v=a2&amp_gsa=1&usqp=mq331AQCCAE%3D#referrer=https%3A%2F%2Fwww.google.com&amp_tf=From%20%251%24s&ampshare=https%3A%2F%2Fwww.geeksforgeeks.org%2Fpython-cloning-copying-list%2F
26th Apr 2019, 9:27 AM
Ayush Sinha
Ayush Sinha - avatar