Copy depth
s=[[1,2],'fgfgf','cx'] s3=s.copy() print(s) print(s3)
test
D:\python\python.exe D:/untitled/dir/for.py [[1, 2], 'fgfgf', 'cx'] [[1, 2], 'fgfgf', 'cx'] Process finished with exit code 0
Shallow copy of the modified
s=[[1,2],'fgfgf','cx'] s3=s.copy() print(s3) s3[1]='chhgghg' print(s) print(s3)
test
D:\python\python.exe D:/untitled/dir/for.py [[1, 2], 'fgfgf', 'cx'] [[1, 2], 'fgfgf', 'cx'] [[1, 2], 'chhgghg', 'cx'] Process finished with exit code 0
Shallow copy of the list of changes
s=[[1,2],'fgfgf','cx'] s3=s.copy() print(s3) s3[0][1]='chhgghg' print(s) print(s3)
test
D:\python\python.exe D:/untitled/dir/for.py [[1, 2], 'fgfgf', 'cx'] [[1, 'chhgghg'], 'fgfgf', 'cx'] [[1, 'chhgghg'], 'fgfgf', 'cx'] Process finished with exit code 0
Shallow copy replication layer
Deep copy
haha = ['cx',123,[15000,9000]] wit = copy.deepcopy(haha) wit[0] = 'cd' wit[1] = 6666 wit[2][1] = 1999 print(wit) print(haha)
test
D: \ python \ python.exe D: /untitled/dir/for.py [[1, 2], 'fgfgf', 'cx'] [[1, 'chhgghg'], 'fgfgf', 'cx'] [[1, 'chhgghg'], 'fgfgf', 'cx'] [ 'cd', 6666, [15000, 1999]] [ 'cx', 123, [15000, 9000]]