Home > Article > Backend Development > 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'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.")
Run result:
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!