requested_toppings = ['mushrooms', 'onions', 'pineapple']
'mushrooms' in requested_toppings
>>True
检查特定值是否不包含在列表中:使用 not in关键字
#code:
banned_users = ['andrew', 'carolina', 'david']
user = 'marie'
if user not in banned_users:
print(user.title() + ", you can post a response if you wish.")
#ending:
Marie, you can post a response if you wish.
2if
在if 语句中,缩进的作用与for 循环中相同。
if-elif-else 结构,代码示例如下
age = 12
if age < 4:
print("Your admission cost is $0.")
elif age < 18:
print("Your admission cost is $5.")
else:
print("Your admission cost is $10.")