python_ 学习笔记(hello world)

python中的循环语句

循环语句均可以尾随一个else语句块,该块再条件为false后执行一次

如果使用break跳出则不执行。

for it in [1,2,3,4]:
    print(it,end=",")
else:
    print("执行else语句块")
#1,2,3,4,执行else语句块
View Code:不使用break
for it in [1,2,3,4]:
    print(it,end=",")
    if it == 4:
        break
else:
    print("执行else语句块")
#1,2,3,4,
View Code:使用break

猜你喜欢

转载自www.cnblogs.com/bbdr/p/10428775.html