if elif 使用方法的示例
我们再来看看 if elif 使用方法的示例
age=['a','b','c','d']
if 'a' in age:
print("you really like a!")
if 'b'in age:
print("you really like b!")
if 'c' in age:
print("you really like c!")
if 'e' in age:
print("you really like e!")
输出结果如下:
you really like a
you really like b
you really like c
再看凡云阁的一段关于年龄测试的代码:
age=17
if age<2:
price="婴儿"
elif age<4:
price="幼儿"
elif age < 13:
price = "儿童"
elif age<20:
price="青少年"
elif age<65:
price="成年人"
else:
price="老年人"
print(F"你是{price}!")
输出结果为:
你是青少年!