- 条件测试
#检查是否相等,用 ==。
car = ‘Audi’
car == ‘audi’ - 检查是否不相等,用 !=。
requested_topping = ‘mushrooms’
if requested_topping != ‘anchovies’:
print(“Hold the anchovies!”) - 使用and或者or检查多个条件
#检查特定值是否包含在列表中
banned_users = [‘andrew’, ‘carolina’, ‘david’]
user = ‘marie’
if user not in banned_users:
print(user.title() + “, you can post a response if you wish.”) - 布尔表达式
#布尔值通常用于记录条件,如游戏是否正在运行,或用户是否可以编辑网站的特定内容:
game_active = True
can_edit = False
条件测试
#检查是否相等,用 ==。
car = ‘Audi’
car == ‘audi’
检查是否不相等,用 !=。
requested_topping = ‘mushrooms’
if requested_topping != ‘anchovies’:
print(“Hold the anchovies!”)
使用and或者or检查多个条件
#检查特定值是否包含在列表中
banned_users = [‘andrew’, ‘carolina’, ‘david’]
user = ‘marie’
if user not in banned_users:
print(user.title() + “, you can post a response if you wish.”)
布尔表达式
#布尔值通常用于记录条件,如游戏是否正在运行,或用户是否可以编辑网站的特定内容:
game_active = True
can_edit = False
运行结果:

