根据德摩根定律:
¬(P ˄ Q) ↔ (¬P) ˅ (¬Q)
¬(P ˅ Q) ↔ (¬P) ˄ (¬Q)
在 Python 3.5 中运行时:
A = True
B = True
x = not(A and B)==(not A) or (not B)
y = not(A or B)==(not A) and (not B)
print('x is :', x, '\ny is :' ,y)
返回:
x is : True
y is : False
问题:为什么 y 为 False?
请您参考如下方法:
尝试添加一些括号 - == 的优先级高于 or。
