1. 形式
2.举例说明
x = 4
if x > 1:
print ('x > 1')
if x >2:
print('x >2')
else:
print('x = 1')
print('finish')
x = 4
if x > 1:
print ('x > 1')
elif x >2:
print('x >2')
else:
print(x)
print('finish')
3.输出结果
4.总结
- if与多个else if是分枝情况。只执行其中一条代码,只要第一个if条件成立,即使满足else if的条件也不会执行else
if及else的内容 - if与多个if是并列情况,会顺序执行
参考文献
1.https://blog.csdn.net/qq_37787456/article/details/78548468?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_baidulandingword-1&spm=1001.2101.3001.4242
2.https://blog.csdn.net/weixin_38098192/article/details/81502184?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-4&spm=1001.2101.3001.4242
3.https://blog.csdn.net/qq_45172832/article/details/104141679