您当前的位置:首页 > IT编程 > python
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 |

自学教程:Python 字典(Dictionary) items()方法

51自学网 2023-01-09 15:59:25
  python
这篇教程Python 字典(Dictionary) items()方法写得很实用,希望能帮到您。

描述

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

语法

items()方法语法:

dict.items()

参数

  • NA。

返回值

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

实例

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

实例(Python 2.0+)

#!/usr/bin/python# coding=utf-8 dict = {'Google': 'www.google.com', 'Codercto': 'www.codercto.com', 'taobao': 'www.taobao.com'} print "字典值 : %s" % dict.items() # 遍历字典列表for key,values in dict.items(): print key,values

以上实例输出结果为:

字典值 : [('Google', 'www.google.com'), ('taobao', 'www.taobao.com'), ('Codercto', 'www.codercto.com')]Google www.google.comtaobao www.taobao.comCodercto www.codercto.com

Python 字典(Dictionary) has_key()方法
Python 字典(Dictionary) keys()方法
51自学网自学EXCEL、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。
京ICP备13026421号-1