Python中的not, and, or

logical_operator_lst = [

  ('and 与运算',),

  ('or 或运算',),

  ('not 非运算',),

  ('逻辑运算符的优先级',),

  ('实例',),

  ('练习',),

]

 

and 与运算

  两者为真则为真

  >>>True and True

  True

  其中一个为假,则为假

  >>>True and False

  False

or 或运算

  两者为假则为假

  >>>False or False

  False

  其中一个为真,则为真

  >>>False or True

  True

not 非运算

  颠倒布尔值的结果(PS: True 和 False 都为布尔值(Booleans))

  >>>not True

  False

逻辑运算符的优先级

  not > and > or

  (PS: 同等优先级从左往右进行运算)

 

实例

  >>>not False or True and False

  解析

    先处理not False --> True

    >>>True or True and False

    再处理 True and False -->False

    >>>True or False

    True

 

练习

  >>>b_1 = True or False or True

  >>>b_2 = True and not False

  >>>b_3 = False and True or not True

 

>>>b_1

True

>>>b_2

True

>>>b_3

False

 

转载于:https://www.cnblogs.com/HopenZhang/p/9960124.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值