python 字典items()方法

欢迎关注本人博客:云端筑梦师

描述

Python 字典 items() 方法以列表形式(并非直接的列表,若要返回列表值还需调用list函数)返回可遍历的(键, 值) 元组数组。

语法

Dict.items()

参数

  • NA

返回值

以列表形式返回可遍历的(键, 值) 元组数组。

实例

示例代码:

D = {'Google': 'www.google.com', 'Runoob': 'www.runoob.com', 'taobao': 'www.taobao.com'}
print("字典值 : %s" % D.items())
print("转换为列表 : %s" % list(D.items()))
# 遍历字典列表
for key, value in D.items():# 遍历字典列表
    print(key, value)

上述代码输出:

字典值 : [('Google', 'www.google.com'), ('taobao', 'www.taobao.com'), ('Runoob', 'www.runoob.com')]
Google www.google.com
taobao www.taobao.com
Runoob www.runoob.com
    原文作者:Aurora_Twinkle
    原文地址: https://www.jianshu.com/p/113f8ad7daf2
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞