python dict.item()方法遍历字典

613次阅读
没有评论

python

  1. dict.item()方法返回由一个二元元组成的dict_item类型对象,dict_item类型可以通过,但不能改变。
  2. 二元元组由字典的键值对组成。

    实例

a = {'张无忌': 25, '赵敏': 24}
print(a.items())
print(type(a.items()))
 
for item in a.items():  # item对象由元组构成
    print(item)
    print(type(item))
 
for key, value in a.items():  # 元组由键值对构成
    print(key, value)
    print(type(key), type(value))
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2022-07-11发表,共计308字。
新手QQ群:570568346,欢迎进群讨论 Python51学习