python中的循环语句
循环语句均可以尾随一个else语句块,该块再条件为false后执行一次
如果使用break跳出则不执行。
for it in [1,2,3,4]: print(it,end=",") else: print("执行else语句块") #1,2,3,4,执行else语句块
for it in [1,2,3,4]: print(it,end=",") if it == 4: break else: print("执行else语句块") #1,2,3,4,
循环语句均可以尾随一个else语句块,该块再条件为false后执行一次
如果使用break跳出则不执行。
for it in [1,2,3,4]: print(it,end=",") else: print("执行else语句块") #1,2,3,4,执行else语句块
for it in [1,2,3,4]: print(it,end=",") if it == 4: break else: print("执行else语句块") #1,2,3,4,