A shallow copy can take a husband and daughter-in-law a bank card for example
# python>>> husband = [' Liang ', 123,[10000,6000]] #丈夫的银行卡信息 (name, ID, quota, balance) >>> wife = Husband.copy ( #媳妇和丈夫公用一张银行卡 (the name differs from the ID, but the amount is the same as the balance) >>> wife[0] = ' Yue ' >>> wife[1] = 456>>> wife[2][1]-= #媳妇花费3000 >>> wife[' Yue ', 456, [10000, +]] #显示媳妇余额 >>> husband[' Liang ', 123, [10000, []] #显示丈夫余额
A shallow copy is just a copy of the first layer, a deep copy equivalent to a clone and a deep copy as follows:
Introduced small three, small three spent money daughter-in-law don't know:>>> liang = [' xin ',111,[15000,10000]]>>> yue = liang.copy () >>> yue[' Xin ' , 111, [15000, 10000]]>>> yue[0] = ' Mumu ' >>> yue[1] = 222>>> yue[2][1]-= 5000>>> yue[ ' Mumu ', 222, [15000, 5000]]>>> liang[' Xin ', 111, [15000, 5000]] above is a shallow copy; The following is a deep copy:>>> import copy>>& Gt Xiaosan = Copy.deepcopy (Liang) >>> xiaosan[0] = "* *" >>> xiaosan[1] = 333>>> xiaosan[2][1]-= 1999>>> xiaosan[' * * ', 333, [15000, 3001]] #已经减少啦 >>> liang[' Xin ', 111, [15000, 5000]]>>> yue[' Mumu ', 222, [15000, []] #媳妇不知道
Shallow copy and deep copy in Python