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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
  • 2021-09-11
  • 2022-01-28
  • 2021-11-18
  • 2021-07-26
猜你喜欢
  • 2021-08-19
  • 2021-08-06
  • 2021-06-22
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
  • 1970-01-01
相关资源
相似解决方案