学习内容:
if条件判断和嵌套
思维导图:
https://mubu.com/doc/3FrkC6Cyew
代码仓库:
意外惊喜
多个if语句和 if…elif…的区别
- 多个if语句,程序运行时会遍历所有if;
- if-elif,只要if或后续某一个elif之一满足逻辑值为True,则程序执行完对应输出语句后自动结束该轮if-elif(即不会再去执行后续的elif或else)
if a>10:
print('a nice')
if a>11:
print('a very nice')
if a>=12:
print('a very very nice')
b=12
if b>10:
print('b nice')
elif b>11:
print('b very nice')
elif b>=12:
print('b very very nice')
输出结果:
a nice
a very nice
a very very nice
b nice
a=12
if a>12:
print('a nice')
if a>11:
print('a very nice')
if a>=12:
print('a very very nice')
b=12
if b>12:
print('b nice')
elif b>11:
print('b very nice')
else:
print('b very very nice')
a very nice
a very very nice
b very nice
在本文下方打卡,因为看见所以相信,让大家看见你的成长,帮助大家一起成长!
打卡模板:
姓名:
自学用时:
收获总结:
遇到的难点与问题:
网友评论