if语句知识点总结

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”)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值