首頁  >  文章  >  後端開發  >  python中的elif是什麼意思

python中的elif是什麼意思

尚
原創
2019-07-06 11:47:5254006瀏覽

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相關技術文章,請造訪Python教學欄位進行學習!

以上是python中的elif是什麼意思的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn