条件判断和循环语句
一、条件判断语句
1、格式:
if <条件判断1>:
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。执行命令
elif <条件判断2>:
执行命令2
else:
执行命令3
2、例子:
# 判断分数的等地,多分支 score = int(input("Please input grade(0-100):")) if score > 100: print("grade not more than 100..") elif score >= 90: print("A") elif score >= 80: print("B") elif score >= 60: print("C") elif score >= 0: print("D") else: print("grade more than 0..")
二、循环语句
1、for
格式:
for i in list/dic/tuple/set:
print(i)
1)range
2、while
格式:
while True:
执行代码
1)break
退出循环
2)continue
跳过本次循环,进行下一轮循环
3、while……else……
作用:while语句执行完成(没有break),执行else语句
格式:
while True:
执行命令
else:
执行命令
4、死循环

更多精彩