版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_40244153/article/details/80024183
描述
Python 字典(Dictionary) items() 函数以列表返回可遍历的(键, 值) 元组数组。
语法
items()方法语法:
dict.items()
参数
- NA。
返回值
返回可遍历的(键, 值) 元组数组。
实例
dict = {'Google': 'www.google.com', 'Runoob': 'www.runoob.com', 'taobao': 'www.taobao.com'}
print(dict.items())# 遍历字典列表
for key,values in dict.items():
print(key,values)
以上实例输出结果为:
dict_items([('taobao', 'www.taobao.com'), ('Runoob', 'www.runoob.com'), ('Google', 'www.google.com')])
taobao www.taobao.com
Runoob www.runoob.com
Google www.google.com