Python 字典 items() 方法,,Python 字典


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

>>> D = {‘Google‘: ‘www.google.com‘, ‘Runoob‘: ‘www.runoob.com‘, ‘taobao‘: ‘www.taobao.com‘}>>> print(D.items())dict_items([(‘Google‘, ‘www.google.com‘), (‘Runoob‘, ‘www.runoob.com‘), (‘taobao‘, ‘www.taobao.com‘)])

for 循环

>>> for k,v in D.items():...  print(k,v)...# 执行结果Google www.google.comRunoob www.runoob.comtaobao www.taobao.com

Python 字典 items() 方法

评论关闭