码迷,mamicode.com
首页 > 其他好文 > 详细

dict内部方法

时间:2016-01-26 20:25:50      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

代码:

#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‘])

 技术分享

dict内部方法

标签:

原文地址:http://www.cnblogs.com/kamil/p/5161255.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!