Reputation: 11
Why shallow copy working in different for nested list elements and non nested list elements? I don't understand why it is doing like this.
It is doing shallow copy function is working in two different ways:
here I am providing the code for that. please give me clarity on this. with graphics possibly.
lst_1 = [1,2,[3,4],5]
lst_2 = lst_1.copy()
lst_1[2][0] = 'Now'
lst_2[0]='haha'
print(lst_1)
print(lst_2)
output is:
[1, 2, ['Now', 4], 5]
['haha', 2, ['Now', 4], 5]
Upvotes: 1
Views: 21