Differentiate between deep and shallow copy in python?
Answer / Shailesh Kumar Yadav
In Python, a deep copy creates separate copies of all sub-objects, while a shallow copy maintains references to the original sub-objects.nn```pythonnimport copynlist1 = [1, 2, [3, 4]]nlist2 = copy.deepcopy(list1)nlist3 = copy.copy(list1)nlist1[2][0] = 5nprint(list1) # Output: [1, 2, [5, 4]]nprint(list2) # Output: [1, 2, [3, 4]]nprint(list3) # Output: [1, 2, [5, 4]]
| Is This Answer Correct ? | 0 Yes | 0 No |
Tell me how memcached should not be used in your python project?
What is the optional statement used in a try except statement in Python?
What happens when you execute python == python?
How python maintains conditional blocks?
What does the ‘yield’ keyword do?
How do you calculate the length of a string?
What is the most popular ide for python?
Why do array indexes start with 0 in most languages?
Why is python 2 still used?
When do you use list vs. tuple vs. dictionary vs. set?
How do I avoid having python class data shared among instances?
Is there a switch or case statement in python?