#if-elif-else
alien_color="green"
if alien_color == "yellow": #检查是否相等
print("this palyer is 5")
elif alien_color == "green":
print("this palyer is 10")
else:
print("this palyer is 15")
#if设置独立的条件
fruits = ["apple","oranger","bananas"]
if "apple" in fruits:
print("You really like bananas")
if "bananas" in fruits:
print("You really like bananas")
#先检查列表是否为空,再对列表中各元素进行指定操作
user_names = ["yaya","sunda","lele","admin","weilai"]
if user_names:
for user_name in user_names:
if user_name == "admin":
print("Hello admin, would you like to see a status report?")
else:
print(user_name+", welcome!")
else:
print("We need to find some users!")
#检查用户名
current_users = ["yaya","sunda","lele","admin","weilai"]
new_users = ["xiaohui","xiaohua","xiaohei","yaya","LeLE"]
for new_user in new_users:
if new_user.lower() in current_users:
print("This name exists")
else:
print("This name not exists")
标签:语句,users,Python,bananas,else,user,print,name From: https://www.cnblogs.com/chaimy/p/17066529.html