大连249建站之家免费精品网站自助建设系统平台免费微
首页 >> 技术分享 >>技术干货 >> python 循环技巧
详细内容

python 循环技巧

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.


联系我们
更多

联系电话:0411-66373325

联系地址:大连市沙河口区富民广场

公司邮箱:2058793689@qq.com

备案信息:Copyright © 2016-2025,www.my249.com,All rights reserved

辽ICP备17015910号-1

seo seo