广告

# 分支判断:if...else...
a = 2
b = 3
if a > b:
    print('a max!')
else:
    print("b max!")
# 判断相等和不相等:运算符(==、!=)
stu = 'wangwu'
if stu == 'wangwu':
    print("wangwu,You are on duty today.")
else:
    print("Please call wangwu to duty")

if stu !='zhangsan':
    print("Please call wangwu to duty")
else:
    print("you are on duty today.")
# 判断包含关系:in 和 not in
b = 'hello world'
if 'hello' in b:
    print('Contain')
else:
    print('Not Contain')
# 判断布尔类型
c = True
if c:
    print('c is True')
else:
    print('c is false')

# 多重判断
res = 72
if res >= 90:
    print('优秀')
elif res >= 70 :
    print('良好')
elif res >=60 :
    print('及格')
else:
    print('不及格')
python if not语句(python if __name__==’main’)插图

广告