2025年6月4日 星期三 乙巳(蛇)年 三月初八 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 编程开发 > Python

Python 中 dict 字典遍历方法

时间:12-14来源:作者:点击数:4

Python 中 dict 字典遍历方法如下:

  1. for in
  2. items
  3. iteritems
  • >>> dict={"name":"python","english":33,"math":35}
  • >>> dict
  • {'name': 'python', 'math': 35, 'english': 33}
  • >>> for i in dict:
  • ... print "dict[%s]"%i,dict[i]
  • ...
  • dict[name] python
  • dict[math] 35
  • dict[english] 33
  • >>> for i in dict:
  • ... print dict[i]
  • ...
  • python
  • 35
  • 33
  • >>> for (k,v) in dict.items():
  • ... print "dict[%s]="%k,v
  • ...
  • dict[name]= python
  • dict[math]= 35
  • dict[english]= 33
  • >>> for (k,v) in dict.items():
  • ... print k,v
  • ...
  • name python
  • math 35
  • english 33
  • >>> for k,v in dict.iteritems():
  • ... print "dict[%s]="%k,v
  • ...
  • dict[name]= python
  • dict[math]= 35
  • dict[english]= 33
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门
本栏推荐