#1
husband =['xiaohu',123,[15000,9000]] wife = husband.copy() print(husband) print(wife) #2
wife[0]='xiaopang' print(husband) print(wife) #3
wife[1]='315' print(husband) print(wife) #4
husband[2][1] -=3000 print(husband) print(wife)
代码可能让新人头昏,于是我画了个图。
深拷贝:全部克隆,深拷贝需要一个单独的模块copy。 copy.copy() #shallow浅拷贝 copy.deepcopy() #深拷贝
浅拷贝:只拷贝第一层