Python中的逻辑语句
优先等级: not > and > or
python中都是从左到右去判断条件的
逻辑语句之and
True and True , True and False
假如左条件为真 会去判断右条件为是否为假;为真的话则返回又条件的结果 为假的话就返回右边的假值
False and True , False and False
假如左条件为假 那么直接返回左边的假值 不管右边是真假 只要左条件为假的话直接返回
逻辑语句之or
True and True , True and False
假如左条件为真直接返回左条件结果
False and True , False and False
假如左条件为假 会去判断右条件的真假 为真的话直接返回右条件的结果 为假的话返回右边假值的结果
逻辑语句之not
最后结果为True的话就反转为False 反之也是一样的
例题:
3.下列结果是什么?
1)、6 or 2 > 1 6
2)、3 or 2 > 1 3
3)、0 or 5 < 4 False
4)、5 < 4 or 3 3
5)、2 > 1 or 6 True
6)、3 and 2 > 1 True
7)、0 and 3 > 1 0
8)、2 > 1 and 3 3
9)、3 > 1 and 0 0