Monday, March 30, 2020

Deep copy in python language

import copy

l1=[10,20,[30,40],50]
#l2=l1.copy()
#it dnot work for list inside another list
l2=copy.deepcopy(l1)

l2[2][0]=70
print("l2:",l2)
print("l1:",l1)

output:
l2: [10, 20, [70, 40], 50]
l1: [10, 20, [30, 40], 50]



related links:

shallow copy in python

No comments:

Post a Comment

python class topic video