脚本宝典收集整理的这篇文章主要介绍了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相关技术文章,请访问Python教程栏目进行学习!
以上就是python中的elif是什么意思的详细内容,更多请关注脚本宝典其它相关文章!
以上是脚本宝典为你收集整理的python中的elif是什么意思全部内容,希望文章能够帮你解决python中的elif是什么意思所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。