网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的范文:

 

标题 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.
随便看

 

在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/23 15:46:17