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