python字典的get函数和iteritems函数
来源:互联网 发布:界面汉化软件 编辑:程序博客网 时间:2024/06/04 18:24
1.get()
当我们获取字典里的值的时候,一个是通过键值对,即dict['key'],另一个就是dict.get()方法。
例如:
>>> dict = {'a':'AA', 'b':'BB', 'c':'CC'}>>> dict['a']'AA'>>> dict.get('a')'AA'
get()方法语法:
dict.get(key, default=None)
key -- 字典中要查找的键。
default -- 如果指定键的值不存在时,返回该默认值。
例如:
>>> dict.get('d','error')'error'
2.iteritems()
python字典中还存在items()方法。两者有些许区别。
items方法是可以将字典中的所有项,以列表方式返回。
iteritems方法与items方法相比作用大致相同,只是它的返回值不是列表,而是一个迭代器。
>>> d = {'1':'one', '2':'two', '3':'three'}>>> x = d.items()>>> x[('1', 'one'), ('3', 'three'), ('2', 'two')]>>> type(x)<type 'list'>>>> y = d.iteritems()>>> y<dictionary-itemiterator object at 0x025008A0>>>> type(y)<type 'dictionary-itemiterator'>
0 0
- python字典的get函数和iteritems函数
- python : items()和iteritems()函数
- python中items()和iteritems()函数的用法
- dict的items函数和iteritems函数
- python 字典 get(),items(),iteritems()方法
- python 字典访问 items()和iteritems()的区别
- python字典中items()和iteritems()的区别
- Python字典中items()和iteritems()区别
- 关于python 字典item iteritems的区别
- python字典get函数陷阱
- Python 字典(Dictionary) get()以及operator.itemgetter函数
- Python中的iteritems()和items()
- python字典sort和min函数的用法
- Python字典内置函数和方法
- python之字典和函数参数
- PYTHON字典常用函数
- python函数与字典
- python字典,集合,函数
- 自己打包程序报错问题查找思路
- js图片轮播可控制是否循环轮播,点击左右按钮切换
- android AsyncTask
- Log4j 日志文件Linux/Mac/Windows通用存放位置设置
- C#修饰符详解
- python字典的get函数和iteritems函数
- Keep On Movin
- 7月
- js 时间戳转yyyy-MM-dd
- hdu1006 Tick and Tick
- 基于Zxing的二维码生成和二维码扫描
- 使用java正则表达式去掉多余的.与0
- 做一个GPSCar类,要求继承Car类,并实现GPS接口
- 关于zepto.js的移动端拖拽写法