python中的elif是什么意思-Python教程

资源魔 38 0

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.")

运转后果:

1.jpg

更多Python相干技巧文章,请拜访Python教程栏目进行学习!

以上就是python中的elif是甚么意义的具体内容,更多请存眷资源魔其它相干文章!

标签: python教程 python编程 python使用问题 python中elif是什么意思

抱歉,评论功能暂时关闭!