Python - Shallow and Deep Copy

preview_player
Показать описание
Python - Shallow and Deep Copy
Lecture By: Mr. Arnab Chakraborty, Tutorials Point India Private Limited
Рекомендации по теме
Комментарии
Автор

Shallow copy uses same same memory of old_list to new_list
But Deep copy is creating new memory for new_list.
Right?

ALLINONE-fhpw
Автор

Thank you so much, your tutorials are fantastic. You have helped me so much with my studies. I really appreciate it. Best regards

louisecrowe
Автор

why do people use shallow copy? what are its uses, if its not doing recursively?

avvarutheja
Автор

I have a doubt, why is [4, 4, 4] not appended to the new_list ??

creativeBrains
Автор

Dear Sir, I have one question about deepcopy if you look at the example below how is it that after deepcoy id of the value of two "different objects" after deepcopy the id of value are the same (line 8 and 9) so here it still seems to be the same element (value) from the list shared by two different objects:

1. import copy
2. old_list = [[1, 2], [3, 4], [5, 6]]
3. deep_list = copy.deepcopy(old_list)
4. print(old_list, 'old_list - deepcopy')
5. print(deep_list, 'deep_list')
6. print(id(old_list), 'id old_list after deepcopy')
7. print(id(deep_list), 'id deep_list')
8. print(id(old_list[1][1]), 'id old_list [1][1]')
9. print(id(deep_list[1][1]), 'id deep_list[1][1]')
10. old_list[1][1] = 'BB'
11. print(old_list, 'old_list - deepcopy')
12. print(deep_list, 'deep_list')
13. print(id(old_list), 'id old_list after deepcopy')
14. print(id(deep_list), 'id deep_list')

Output:
[[1, 2], [3, 4], [5, 6]] old_list
[[1, 2], [3, 4], [5, 6]] deep_list
3419752 id old_list after deepcopy
3778640 id deep_list
267442400 id old_list [1][1]
267442400 id deep_list[1][1]
[[1, 2], [3, 'BB'], [5, 6]] old_list - deepcopy
[[1, 2], [3, 4], [5, 6]] deep_list
3419752 id old_list after deepcopy
3778640 id deep_list

Thank you in advance

mikijasar
Автор

cha cha har cheez p video bnana zruri nhe h

anmol