Python--循环跳出

import sys
# 1. else 配对循环,当条件不成立时执行
a = [1, 2, 3, 4, 5, ]
for i in range(0, len(a)):
    print(a[i])
else:
    print("循环完了跳出")
print("--------------------------")
# sum = 0
total = 0  # sum打了波浪线,因为系统自身有sum函数所以会提示波浪线
while i < 101:
    total += i
    i += 1
else:
    print(total)
sys.exit(0)
发布了18 篇原创文章 · 获赞 11 · 访问量 1202

猜你喜欢

转载自blog.csdn.net/konmor/article/details/102486073
今日推荐