python之if语句以及条件测试( and 、or、in、not in)

1.and 、or、in、not in

'''
条件测试
'''
#单个条件测试
age0 = 22
print(age0>=22) # True

#多个条件测试 and
age0 = 22
age1 = 18
print(age0>=21 and age1>=21) #False

#多个条件测试 or
print(age0>=21 or arg0>=21) #True
 
#in和not in(检查特定值是否在列表中)
fruits = ['apple','banana','orange']
print('apple' in fruits) #True
print('apple' not in fruits) #False

2.if语句

'''
简单的if语句(仅包含一个测试和一个操作)
'''
height = 1.7
if height>=1.3:
    print('高')
'''
if-else
'''
height = 1.8
if height<=1.4:
    print('免票')
else:
    print('全票')
#最后输出全票
'''
if-elif
'''
height = 1.5
if height>=1.4:
    print('嘿嘿')
elif height>=1.3:
    print('呵呵')
#最后输出嘿嘿
'''
if-elif-else
'''
height = 1.8
if height<=1.4:
    print('免票')
elif height>1.4 and height<=1.7:
    print('半票')
else:
    print('全票')
#最后输出全票

你可能感兴趣的:(python)