Making True Copy


☞ There are two types of copy :

1. Shallow Copy
2. Deep Copy

Shallow Copy : Assignment operator(=) makes the two variables point to the one list in memory called shallow copy.

Example :
 
L1=[10, 20, 30]
L2 = L1         #Shallow Copy
print(id(L1), id(L2))
Output :
1582527544128      1582527544128
Note : Address of both the list will be the same i.e. they are pointing to the same object.

Deep Copy : To make a true copy of the list, we use list() as follows.

Example :
 
L1=[10, 20, 30]
L2 = list(L1)         #True Copy
print(id(L1), id(L2))
Output :
1582527541632     1582483721536
Note : Address of both the list will be different i.e. they are pointing to different objects.