python items()方法如何使用?
Python 字典(Dictionary) items()方法
Python 字典(Dictionary) items() 函数以列表返回可遍历的(键, 值) 元组数组。
推荐:《Python教程》
语法
items()方法语法:
dict.items()
参数
NA。
返回值
返回可遍历的(键, 值) 元组数组。
以下实例展示了 items()函数的使用方法:
实例(Python 2.0+)
#!/usr/bin/python # coding=utf-8 dict = {'Google': 'HdhCmsTestgoogle测试数据', 'Runoob': 'HdhCmsTestgxlcms测试数据', 'taobao': 'HdhCmsTesttaobao测试数据'} print "字典值 : %s" % dict.items() # 遍历字典列表 for key,values in dict.items(): print key,values
以上实例输出结果为:
字典值 : [('Google', 'HdhCmsTestgoogle测试数据'), ('taobao', 'HdhCmsTesttaobao测试数据'), ('Runoob', 'HdhCmsTestgxlcms测试数据')] Google HdhCmsTestgoogle测试数据 taobao HdhCmsTesttaobao测试数据 php HdhCmsTestgxlcms测试数据
以上就是python items()方法如何使用的详细内容,更多请关注Gxlcms其它相关文章!
查看更多关于python items()方法如何使用的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did78862