python 循环技巧
2015-04-26 13:35
309 查看
摘自:超级无敌python教程
dict的循环:
list的循环:
多个list的循环:
dict的循环:
>>> knights = {'gallahad': 'the pure', 'robin': 'the brave'} >>> for k, v in knights.items(): ... print k, v ... gallahad the purerobin the brave
list的循环:
>>> for i, v in enumerate(['tic', 'tac', 'toe']): ... print i, v ... 0 tic 1 tac
多个list的循环:
>>> questions = ['name', 'quest', 'favorite color'] >>> answers = ['lancelot', 'the holy grail', 'blue'] >>> for q, a in zip(questions, answers): ... print 'What is your %s? It is %s.' % (q, a) ... What is your name? It is lancelot. What is your quest? It is the holy grail.
相关文章推荐
- python循环技巧
- Python数据结构的一些技巧、数据结构练习、循环与判断练习题
- python循环技巧
- Python列表生成器的循环技巧分享
- Python -- 循环技巧(Looping Techniques)
- 【python技巧系列】在循环中处理异常并继续运行
- python循环技巧
- python 循环技巧
- Python的for和break循环结构中使用else语句的技巧
- Python列表生成器的循环技巧分享
- Python学习笔记-数据结构之循环技巧
- Python减少循环层次和缩进的技巧分析
- Python学习笔记:循环技巧
- Python笔记7:循环技巧和控制语句
- Python的for和break循环结构中使用else语句的技巧
- Python减少循环层次和缩进的技巧分析
- Python循环的技巧
- python函数定义中的参数问题、循环技巧
- Python实用技巧---列表推导式(轻量级循环)与map
- python学习2——if语句、elif、if嵌套、while循环、while嵌套