python笔记(四)

检查多个条件

  1. 使用and 检查多个条件
age_0 = 22
age_1 = 18
print(age_0 >= 21 and age_1 >= 21 )
age_1 = 22
print(age_0 >= 21 and age_1 >= 21)
  1. 使用 or 检查多个条件
age_0 = 22
age_1 = 18
print(age_0 >= 21 or age_1 >= 21 )
age_1 = 22
print(age_
  1. 要判断特定的值是否已包含在列表中,可使用关键字in
requested_toppings = ['mushrooms', 'onions', 'pineapple']
print('mushrooms' in requested_toppings)
print('pepperoni' in requested_toppings)
  1. 检查特定值是否不包含在列表中,可使用关键字not in
banned_users = ['andrew', 'carolina', 'david']
user = 'marie'
if user not in banned_users:
    print(user.title() + ", you can post a response if you wish.")
  1. 布尔表达式
    与条件表达式一样,布尔表达式的结果要么为True ,要么为False
game_active = True 
can_edit = False

注:函数lower():可将变量的值转换为小写,同时不会修改存储在变量 中的值

car = 'Audi'
print(car.lower())
print(car)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值