copy & deepcopy
Në shqip përdoret i njëjti emër.
ShpjegimiSQ
b = a s'krijon kopje — të dy emrat tregojnë te e njëjta listë. copy.copy() bën kopje „të cekët“ (listat brenda mbeten të përbashkëta), ndërsa copy.deepcopy() kopjon gjithçka deri në fund.
EnglishEN
b = a doesn't create a copy — both names point to the same list. copy.copy() makes a “shallow” copy (inner lists stay shared), while copy.deepcopy() copies everything all the way down.
Si ta mendosh
copy është si ta fotokopjosh vetëm kopertinën e dosjes; deepcopy fotokopjon edhe çdo fletë brenda.
Lexoje në anglisht
copy is like photocopying just the folder's cover; deepcopy photocopies every sheet inside too.
Shembull kodipython
import copy
a = [[1, 2], [3]]
b = copy.deepcopy(a)
b[0].append(9)
print(a) # [[1, 2], [3]] — i paprekur