list = ['zz','ss']
list.append(list)
print(id(list[2]))
print(id(list[2][0]))
print("1 :",list)
list.append(list)
print(id(list[3]))
print(id(list[3][0]))
print("2 :",list)
结果:
140463746455816
140463746410736
1 : ['zz', 'ss', [...]]
140463746455816
140463746410736
2 : ['zz', 'ss', [...], [...]]
参考:
list = ['zz','ss']
list.append(copy.deepcopy(list))
print("1 :",list)
list.extend(list)
print("2 :",list)
结果
1 : ['zz', 'ss', ['zz', 'ss']]
2 : ['zz', 'ss', ['zz', 'ss'], 'zz', 'ss', ['zz', 'ss']]
copy与deepcopy的区别
- 浅拷贝:拷贝这个对象的引用地址
- 深拷贝:拷贝对象的内容
标签:Python,list,列表,ss,zz,print,id,append From: https://www.cnblogs.com/z977690557/p/17415718.html