品易云推流 关闭
文章详情页
文章 > Python基础教程 > python dict.item()方法遍历字典

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

Python dict.item

头像

小妮浅浅

2021-06-07 16:20:225763浏览 · 0收藏 · 0评论

  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))

以上就是python dict.item()方法遍历字典的方法,希望对大家有所帮助。更多Python学习指路:python基础教程

推荐操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图