当前位置:Gxlcms > Python > python items()方法如何使用

python items()方法如何使用

时间:2021-07-01 10:21:17 帮助过:86人阅读

python items()方法如何使用?

Python 字典(Dictionary) items()方法

Python 字典(Dictionary) items() 函数以列表返回可遍历的(键, 值) 元组数组。

推荐:《Python教程》

语法

items()方法语法:

  1. dict.items()

参数

NA。

返回值

返回可遍历的(键, 值) 元组数组。

以下实例展示了 items()函数的使用方法:

实例(Python 2.0+)

  1. #!/usr/bin/python
  2. # coding=utf-8
  3. dict = {'Google': 'www.google.com', 'Runoob': 'www.gxlcms.com', 'taobao': 'www.taobao.com'}
  4. print "字典值 : %s" % dict.items()
  5. # 遍历字典列表
  6. for key,values in dict.items():
  7. print key,values

以上实例输出结果为:

  1. 字典值 : [('Google', 'www.google.com'), ('taobao', 'www.taobao.com'), ('Runoob', 'www.gxlcms.com')]
  2. Google www.google.com
  3. taobao www.taobao.com
  4. php www.gxlcms.com

以上就是python items()方法如何使用的详细内容,更多请关注Gxlcms其它相关文章!

人气教程排行