python的ifelse条件判断语句_python if elif else条件判断语句

'''

if elif else条件判断语句,也就是谁成立也就是为True,就会执行谁下面缩进的代码,就像生活中我们做的一些事,

比如这个周日,不加班,去出完,加班了,那就加完班晚上吃大大餐,就是会选择一条路去走。

注意:代码缩进,要么用Tab键缩进,要么用4个空格缩进

if (hello > 8):

print ("hello大于8")

print ("1")

这里两个print从缩进可以看出所属if (hello > 8):

'''

hello = 100

hi = 80

if (hello > 8): #hello值为100,这里hello>8结果True,因此就会打印下面print:hello大于8

print ("hello大于8")

print ("1")

hello = 6 #把hello的值修改为6

if (hello > 8): #这里hello>8结果False,因此就会不打印下面print

print ("hello大于8")

elif (hello > 7): #这里hello>7结果False,因此就会不打印下面print

print ("hello大于7")

else: #else这里就是以上if elif 都不成立就会进来,因此打印了下面print:你好

print ("你好")

print ("2")

'''

输出结果:

hello大于8

1

你好

2

'''

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值