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.com Runoob www.runoob.com taobao www.taobao.com
原文地址:https://www.cnblogs.com/mingerlcm/p/8206090.html
时间: 2024-10-09 11:33:07