Home >Backend Development >Python Tutorial >What does elif in python mean?

What does elif in python mean?

尚
Original
2019-07-06 11:47:5254220browse

What does elif in python mean?

elif is the abbreviation of else if. else and elif statements can also be called clauses, because they cannot be used independently. Both appear inside if, for, and while statements. The else clause can add a choice; the elif clause is used when more conditions need to be checked, and is used together with if and else.

Example:

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

Run result:

What does elif in python mean?

For more Python related technical articles, please visit Python Tutorial Column for learning!

The above is the detailed content of What does elif in python mean?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn