码迷,mamicode.com
首页 > 编程语言 > 详细

python基础-(copy)

时间:2016-12-22 20:27:02      阅读:257      评论:0      收藏:0      [点我收藏+]

标签: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]}

 

python基础-(copy)

标签:ref   deepcopy   mem   copy   span   pre   深拷贝   log   new   

原文地址:http://www.cnblogs.com/tiannan/p/6212354.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!