Python 中的ifelse判断
Python 2017/12/15 20:19:38 点击:不统计
<网f站o学a习s制p作.cn>
#1. Python中if判断,我们常用判断逻辑,我们下面说一下 Python中的if else
score = 91
if score > 90:
print 'score big then 90'
print 'if end'
#2. 这里没有结束if 的符号,通过 4 个空格的缩进符来确定结束if
print 'this is out of if function'
score = 90
#3. if 逻辑判断中的 not ,即非True 的情况
if not score > 90:
print 'score is not big then 90'
print 'if end'
#4. if 中的else
age = 19
if age > 17:
print '青少年,加油'
else: # 一定要注意 这里有个 : 冒号
print '成年人了,努力吧'
#5. if判断中的 elif 也就是 else if
number = 10
if number > 10:
print '对于10'
elif number > 20:
print '大于20'
else:
print '其他情况'
http://%77%77%77%2E%66网站制作%6F学习网%72%61%73%70%2E%63%6E
·上一篇:Python中的数组对象:列表tuple >> ·下一篇:Python 中的循环方法 >>