python 的逻辑关系

NOT | TRUE?
not False -> True
not True -> False

OR | True?
True or True -> True
True or False-> True
False or True -> True
False or False -> False

AND | True?
False and False -> False
False and True -> False
True and False -> False
True and True -> True

Python 具有短路逻辑,也叫‘守卫者模式’,False and 开头直接返回False ; True or 开头直接返回True

NOT OR |True?
not(True or True) -> False
not(True or False)-> False
not(False or True) -> False
not(False or False) -> True

NOT AND | True

!= 不等于
==等于

在判断逻辑关系时,分几步:
1. 找到相等判断的部分(== / !=) ,将其写为(True 或False)
2. 找到括号中and /or ,算他们的值
3. 找到每一个not ,算他们的反值
4. 找到剩下的and /or ,解值
5. 结束,得到只剩一个True/False

True and True
False and True
1 == 1 and 2 ==1
"test" == "test"
1 == 1 or 2 != 1
True and 1 == 1
False and 0 != 0
True or 1==1
"test" == "testing"
1 != 0 and 2 == 1
"test" !="tseting"
"test" == 1
not(True and False)
not(1==1 and 0 != 1)
not(10 == 1 or 1000 == 1000)
not(1 != 10 or 3 == 4)
not ("tseting" == "testing" and "Zed" == "Cool Guy")
1 == 1 and not("testing" == 1 or 1 == 0)
"chunky" == "bacon" and not(3 == 4 or 3 == 3)
3 == 3 and not("testing" == "testing" or "Python" == "Fun")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值