Articles → Python → Deep Copy And Shallow Copy In List In Python
Deep Copy And Shallow Copy In List In Python
Shallow Copy
list1 = []
list2 = []
# shallow copy
list2 = list1.copy()
if (list1 is list2):
print("List1 and List2 is having same reference")
else:
print("List1 and List2 is having different reference")
Output
Deep Copy
list1 = []
list2 = []
# Deep copy
list2 = list1
if (list1 is list2):
print("List1 and List2 is having same reference")
else:
print("List1 and List2 is having different reference")
Output