标签:strong span splay 无限 tin 执行 ssi 表达式 blog
一.if语句
单分支,单重条件判断
语法:
expr_true_suite if expession else expr_false_suite
案例一:
>>> active=1 >>> print(‘service is active‘) if active else print(‘service is inactive‘) service is active
案例二:
>>> x=1 >>> y=2 >>> smaller=x if x < y else y >>> smaller 1
while expression:
suite_to_repeat
注解:重复执行suite_to_repeat,直到expression不再为真
count=0 while (count < 9): print(‘the loop is %s‘ %count) count+=1
count=0 while True: print(‘the loop is %s‘ %count) count+=1
tag=True count=0 while tag: if count == 9: tag=False print(‘the loop is %s‘ %count) count+=1
count=0 while (count < 9): count+=1 if count == 3: print(‘跳出本层循环,即彻底终结这一个/层while循环‘) break print(‘the loop is %s‘ %count)
count=0 while (count < 9): count+=1 if count == 3: print(‘跳出本次循环,即这一次循环continue之后的代码不再执行,进入下一次循环‘) continue print(‘the loop is %s‘ %count)
count=0 while (count < 9): count+=1 if count == 3: print(‘跳出本次循环,即这一次循环continue之后的代码不再执行,进入下一次循环‘) continue print(‘the loop is %s‘ %count) else: print(‘循环不被break打断,即正常结束,就会执行else后代码块‘) count=0 while (count < 9): count+=1 if count == 3: print(‘跳出本次循环,即这一次循环continue之后的代码不再执行,进入下一次循环‘) break print(‘the loop is %s‘ %count) else: print(‘循环被break打断,即非正常结束,就不会执行else后代码块‘)
循环被break打断,即非正常结束,就不会执行else后代码块
标签:strong span splay 无限 tin 执行 ssi 表达式 blog
原文地址:http://www.cnblogs.com/maxiaotiaoshishui/p/7207418.html