and将两个条件语句合二为一;or检查多个条件;not in确定特定的值是否包含在列表中
布尔表达式的结果要么为True要么是False
python只执行if-elif-else结构中的一个代码块;如果执行多个代码块,使用一系列独立的 if语句
最简单的if语句只有一个测试和一个操作
if conditional_text:
dosomething
在if语句将列表名用在条件表达式中,python将在列表至少包含一个元素时返回True,并在列表为空时返回False
requested_toppings=[“li”,“zhang”]
if requested_toppings: #if加列表名
for requested_topping in requested_toppings:
print(“adding”+" “+requested_topping+”.")
print("\nFinished making your pizza")
else:
print(“Are you sure you want a plain pizza”)
names=[“admin”,“zhang”,“cheng”,“dai”,“yao”]
if names: #if加列表名
for name in names:
if name == “admin”:
print(“hello admin,would you like to see a status report”)
else:
print(“hello” + " " + name + “,” + “thank you for logging in again”)
else:
print(“We need to find some users”)
current_users=[“li”,“Dai”,“cheng”,“yao”,“song”]
new_users=[“Li”,“dai”,“zhang”,“zhu”,“cai”]
for new_user in new_users:
if new_user.lower()or new_user.upper() in current_users:
print(new_user+" “+“please input other name”)
else:
print(new_user+” "+“the name is not used”)