您好,欢迎访问一九零五行业门户网

Python中的if、else、elif语句用法简明讲解

下面我们学习if语句,输入下面的代码,确保能够正确运行。
people = 20 cats = 30 dogs = 15 if people cats: print not many cats! the world is saved! if people dogs: print the world is dry! dogs += 5 if people >= dogs: print people are greater than or equal to dogs. if people people: print we should take the cars. elif cars cars: print that's too many buses. elif buses buses: print alright, let's just take the buses. else: print fine, let's stay home then.
运行结果
root@he-desktop:~/mystuff# python ex30.py
we should take the cars.maybe we could take the buses.alright, let's just take the buses.
其它类似信息

推荐信息