返回顶部

收藏

Dictionary copy

更多
#The copy method returns a new dictionary with the same key-value pairs (a 'shallow 
#copy,' since the values themselves are the same, not copies):

x = {'username': 'admin', 'machines': ['foo', 'bar', 'baz']}
y = x.copy()
y['username'] = 'mlh'
y['machines'].remove('bar')
print y

print x

标签:Python,Dictionary

收藏

0人收藏

支持

0

反对

0