字典的复制–copy函数
功能
用法
dict.copy()
-> 该函数无参数, 返回一个一模一样的内存地址不同的字典
代码
代码语言:javascript
复制# coding:utf-8
fruits = {
'apple': 30,
'banana': 50,
'pear': 100
}
real_fruits = fruits.copy()
fruits['apple'] = 60
print(real_fruits)
real_fruits['orange'] = 50
real_fruits.update({'cherry': 100})
print(real_fruits)
# print(fruits)
real_fruits['apple'] = real_fruits['apple'] - 5
print(real_fruits)
real_fruits['pear'] -= 3
print(real_fruits)
real_fruits.clear()
print(real_fruits)
print('第二天......')
real_fruits = fruits.copy()
print(real_fruits)