标签:table 浅拷贝 copy list span min imp print date
from collections.abc import Mapping,MutableMapping from collections.abc import __all__ # dict 属于Mapping类型 a = {} print(isinstance(a,MutableMapping))
a = { "liming1":{"company":"tencent1"}, "liming2":{"company":"tencent2"}, } # clear """ D.clear() -> None. Remove all items from D. """ # a.clear() #copy 浅拷贝 """ D.copy() -> a shallow copy of D """ new_dict = a.copy() new_dict[‘liming1‘][‘company‘] = ‘tencent3‘ print(a) print(new_dict) ########### {‘liming1‘: {‘company‘: ‘tencent3‘}, ‘liming2‘: {‘company‘: ‘tencent2‘}} {‘liming1‘: {‘company‘: ‘tencent3‘}, ‘liming2‘: {‘company‘: ‘tencent2‘}}
# fromkeys new_list = [‘liming1‘,‘liming2‘] new_dict = dict.fromkeys(new_list,{‘company‘:‘tencent‘}) print(new_dict)
# update new_dict.update({‘lisa‘:{"company":"tencent2"}}) new_dict.update({‘liming2‘:{"company":"tencent2"}}) new_dict.update(jenny={‘company‘:‘beijing‘}) new_dict.update([(‘jenny‘,{‘company‘:‘shanghai‘})]) print(new_dict)
标签:table 浅拷贝 copy list span min imp print date
原文地址:https://www.cnblogs.com/richiewlq/p/11073272.html