标签:ref deepcopy mem copy span pre 深拷贝 log new
浅拷贝
import copy dic = { "cpu":[80,], "mem":[80,], "disk":[80,] } print(‘brefore:‘,dic) new_dic = copy.copy(dic) new_dic[‘cpu‘][0] = 50 print(dic) print(new_dic) #brefore: {‘disk‘: [80], ‘mem‘: [80], ‘cpu‘: [80]} #{‘disk‘: [80], ‘mem‘: [80], ‘cpu‘: [50]} #{‘disk‘: [80], ‘mem‘: [80], ‘cpu‘: [50]}
深拷贝
import copy dic = { "cpu":[80,], "mem":[80,], "disk":[80,] } print(‘brefore:‘,dic) new_dic = copy.deepcopy(dic) new_dic[‘cpu‘][0] = 50 print(dic) print(new_dic) #brefore: {‘disk‘: [80], ‘cpu‘: [80], ‘mem‘: [80]} #{‘disk‘: [80], ‘cpu‘: [80], ‘mem‘: [80]} #{‘disk‘: [80], ‘cpu‘: [50], ‘mem‘: [80]}
标签:ref deepcopy mem copy span pre 深拷贝 log new
原文地址:http://www.cnblogs.com/tiannan/p/6212354.html