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相干技术文章,请接见Python教程栏目举行进修!
以上就是python中的elif是什么意义的细致内容,更多请关注ki4网别的相干文章!