ホームページ  >  記事  >  バックエンド開発  >  Pythonのエリフとはどういう意味ですか?

Pythonのエリフとはどういう意味ですか?

尚
オリジナル
2019-07-06 11:47:5254085ブラウズ

Pythonのエリフとはどういう意味ですか?

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&#39;t dicide.")
  
  
if buses > cars: 
  print ("That&#39;s too many buses.")
elif buses < cars: 
  print ("Maybe we could take the buses.")
else: 
  print ("We still can&#39;t decide.")
  
  
if people > buses: 
  print ("Alright, let&#39;s just take the buses.")
else: 
  print ("Fine, let&#39;s stay home then.")

実行結果:

Pythonのエリフとはどういう意味ですか?

Python 関連の技術記事の詳細については、Python チュートリアル をご覧ください。学びのコラム!

以上がPythonのエリフとはどういう意味ですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。