Python-复制字典的方式
字典是无序,可更改和索引的集合。在Python中,字典用大括号括起来,并且具有键和值。他们copy()方法返回字典的浅表副本。
示例
#creating a dictionary
original = {1:'vishesh', 2:'python'}
# copying using copy() function
new = original.copy()
# removing all elements from the list Only new list becomes empty as #copy() does shallow copy.
new.clear()
print('new: ', new)
print('original: ', original)
# between = and copy()original = {1:'Vishesh', 2:'python'}
# copying using copy() function
new = original.copy()
# removing all elements from new list
# and printing both
new.clear()
print('new: ', new)
print('original: ', original)
original = {1:'one', 2:'two'}
# copying using =
new = original
# removing all elements from new list
# and printing both
new.clear()
print('new: ', new)
print('original: ', original)输出结果
('new: ', {})
('original: ', {1: 'vishesh', 2: 'python'})
('new: ', {})
('original: ', {1: 'Vishesh', 2: 'python'})
('new: ', {})
('original: ', {})热门推荐
1 训练狗狗搜寻
2 如何训练狗狗装死
3 狗狗训练书
6 怎么训练狗狗拜年
8 狗狗训练游戏
10 狗狗嗅觉训练
11 怎么训练狗狗在笼子里不叫
12 怎么训练狗狗站立走路
13 怎么训练狗狗在马桶上
14 狗狗尿尿怎么训练
15 训练狗狗用品
16 泰迪狗狗的训练方法大小便
17 训练狗狗可以打吗
18 王曼丽的狗狗训练