"""
continue 语法
"""
# 累加1- 100之间的数字,能被5整除的数字
# sum_value = 0
# for item in range(1, 101):
# 满足条件则累加
# if item % 5 == 0:
# sum_value += item
sum_value = 0 for item in range(1, 101): # 不满足条件则跳过本次循环,继续下次循环。 if item % 5 != 0: continue sum_value += item print(sum_value)
# 练习1:累加10 - 50之间个位不是2,5,9的整数 sum_value = 0 for item in range(10, 51): unit = item % 10 # 个位是2,5,9的整数,则跳过。 if unit == 2 or unit == 5 or unit == 9: # 不累加 continue sum_value += item print(sum_value)
标签:入门,Python,sum,value,累加,item,continue,unit From: https://www.cnblogs.com/Remick/p/17068895.html