当前位置: 代码迷 >> 综合 >> Python基础学习--- 字典 items() 方法
  详细解决方案

Python基础学习--- 字典 items() 方法

热度:4   发布时间:2024-01-09 17:59:24.0

描述

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

语法

items()方法语法:


dict.items()

参数

  • NA。

返回值

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

实例

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

#!/usr/bin/python3dict = {'Name': 'Runoob', 'Age': 7}print ("Value : %s" %  dict.items())
以上实例输出结果为:
Value : dict_items([('Age', 7), ('Name', 'Runoob')])



遍历例子:

dict = {'Name': 'Runoob', 'Age': 7}
for i,j in dict.items():print(i, ":\t", j)
输出:
Name :   Runoob
Age :    7



  相关解决方案