逻辑运算符
逻辑运算符
and or not
结果:
and : 与 并且
A and B
True and True ------->True
True and False --------->False
False and True -----------> False
False and False -----------> False
or : 或 或者 只要有一侧为真结果就为真
A or B
True and True ------->True
True and False --------->True
False and True -----------> True
False and False -----------> False
not 非 取反
not True -----> False
not False ----> True
验证and
a = 1
b = 3
print(b and a)
c = 0
print(c and a)
往往是一种关系进行and比较
print(a > c and a < b)
print(a == c and a < b)
验证or
a = 1
b = 3
c = 0
print('#' * 20)
print(b or a)
print(a or b)
下面看下如果有0参与了会怎样
print(c or b)
print(a > c and a < b)
print(a == c and a < b)
结果
验证not
a = 1
b = 3
c = 0
flag = True
print(not flag)
print(not (a>c))
|