python中的elif是什么意思


本文摘自php中文网,作者尚,侵删。

elif是else if的简写。else和elif语句也可以叫做子句,因为它们不能独立使用,两者都是出现在if、for、while语句内部的。else子句可以增加一种选择;而elif子句则是需要检查更多条件时会被使用,与if和else一同使用。

实例:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

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

运行结果:

1.jpg

更多Python相关技术文章,请访问Python教程栏目进行学习!

以上就是python中的elif是什么意思的详细内容,更多文章请关注木庄网络博客!!

相关阅读 >>

Python怎么创建文件夹

Python3怎么不换行输出

Python os模块使用详解

Python下如何实现文件的修改操作?(附示例)

实例详解利用Python暴力破解zip文件口令的方法

Python输出九九乘法表

Python语言有哪两种编程方式

Python函数(一)什么是函数

Python中多线程与多进程的区别

Python多重继承中的菱形继承

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...