当前位置: 首页 > 图灵资讯 > 行业资讯> python dict.item()方法遍历字典

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

发布时间:2024-07-21 20:36:27

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

  2. 二元组由字典的键值对组成。

    实例

a={'张无忌':25,'赵敏':24}
print(a.items())
print(type(a.items()))

foritemina.items():#item对象由元组组成
print(item)
print(type(item))

forkey,valueina.items():#元组由键对组成
print(key,value)
print(type(key),type(value))

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

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

相关文章

如何让vim支持python3

如何让vim支持python3

2025-09-12
python2.7和3.6区别有哪些

python2.7和3.6区别有哪些

2025-09-12
python3有serial库吗

python3有serial库吗

2025-09-12
python中w、r表示什么意思

python中w、r表示什么意思

2025-09-12
python中如何把list变成字符串

python中如何把list变成字符串

2025-09-12
python命名空间是什么

python命名空间是什么

2025-09-12