代码:
#dict内部方法
vdic={'name':'kamil','age':23}
print(dir(vdic))
vdic1 = vdic.copy()#copy(self):浅拷贝
print(vdic1)
print(vdic.get('name'))#get(self, k, d=None):根据key获取值,d是默认值
print(vdic.items())#items(self):所有项的列表形式
print(vdic.keys())
结果:
['__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']
{'age': 23, 'name': 'kamil'}
kamil
dict_items([('age', 23), ('name', 'kamil')])
dict_keys(['age', 'name'])