python中elif指的是什么-创新互联
这篇文章给大家分享的是有关python中elif指的是什么的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。

elif是else if的简写。else和elif语句也可以叫做子句,因为它们不能独立使用,两者都是出现在if、for、while语句内部的。else子句可以增加一种选择;而elif子句则是需要检查更多条件时会被使用,与if和else一同使用。
实例:
people = 30
cars = 40
buses = 15
if cars > people:
print( "We should take the cars.")
elif cars < people:
print ("We should not take the cars.")
else:
print ("We can't dicide.")
if buses > cars:
print ("That's too many buses.")
elif buses < cars:
print ("Maybe we could take the buses.")
else:
print ("We still can't decide.")
if people > buses:
print ("Alright, let's just take the buses.")
else:
print ("Fine, let's stay home then.")运行结果:

感谢各位的阅读!关于python中elif指的是什么就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!
分享标题:python中elif指的是什么-创新互联
本文网址:http://www.jxjierui.cn/article/dsdcgj.html


咨询
建站咨询
