xiaowu7890

Python中从字典获取键与items()(学习笔记)

keys()描述

Python 字典(Dictionary) keys() 函数以列表返回一个字典所有的键。

语法

dict.keys()

例题

users = {
\'username\':\'efermi\',
\'first\':\'enrico\',
\'last\':\'fermi\',
}
for dict_key in users.keys():
print(dict_key)
输出结果:

username
first
last

items()描述

Python 字典(Dictionary) items() 函数以列表返回可遍历的(键, 值) 元组数组。

语法

dict.items()

例子

users = {
\'username\':\'efermi\',
\'first\':\'enrico\',
\'last\':\'fermi\',
}
for key,value in users.items():
print("\nKey:" + key)
print("Value:" + value)
输出结果:

Key:username
Value:efermi

Key:first
Value:enrico

Key:last
Value:fermi

posted on 2018-08-24 17:30  shallow_smile  阅读(19551)  评论(0编辑  收藏  举报
 

分类:

技术点:

相关文章:

  • 2021-11-04
  • 2021-11-04
  • 2021-10-06
  • 2021-11-04
  • 2021-08-19
  • 2021-09-11
  • 2021-05-20
  • 2021-11-15
猜你喜欢
  • 2021-11-04
  • 2021-11-04
  • 2021-11-15
  • 2018-11-14
  • 2021-11-04
  • 2018-08-27
  • 2021-11-15
相关资源
相似解决方案