python初学笔记(五)---实例学python

来源:互联网 发布:免费手机工作日志软件 编辑:程序博客网 时间:2024/06/05 18:41
    10,break语句:

        break语句是用来终止循环语句的,即,哪怕循环条件没有到false或序列还没有被完全递归,也停止执行循环语句;

         一个重要的解释是,如果你从for或者while循环中终止,任何对应循环else块将不执行。
while True:s = raw_input('enter something:')if s == 'quit'breakprint 'length of the string is',len(s)print 'done'

保存退出;

$ python break.py enter something:whilelength of the string is 5enter something:hellolength of the string is 5enter something:quitdone


    11,continue语句:、

        continue语句被用来告诉python跳过当前循环块中剩下的语句,然后继续下一轮循环:

while True:s = raw_input('enter something')if s == 'quit':breakif len(s) < 3:continueprint 'input is of sufficient length'
保存退出;

$ python continue.py entry something:123input is of sufficient lengthentry something:werinput is of sufficient lengthentry something:quiteinput is of sufficient lengthentry something:quit

if、while和for以及与它们相关的break和continue语句。它们是Python中最常用的部分,熟悉这些控制流是应当掌握的基本技能。

原创粉丝点击