我正在做这本书“以艰难的方式学习python”。在练习 27 ( http://learnpythonthehardway.org/book/ex27.html ) 中,它从布尔代数开始。
所以我的问题是:为什么是not(True and False)真的?
我怎么理解的,应该是一样的False and True。
我正在做这本书“以艰难的方式学习python”。在练习 27 ( http://learnpythonthehardway.org/book/ex27.html ) 中,它从布尔代数开始。
所以我的问题是:为什么是not(True and False)真的?
我怎么理解的,应该是一样的False and True。
您的解释不正确,请参阅德摩根定律;具体来说,连词的否定是否定的析取。
not (True and False)( a negation of a conjunction == not(a and b)) 等价于False or True( a disjunction of the negations == (not a) or (not b)); 注意从and到的切换or!
您还可以制定以下步骤:
not(True and False)
True and False->Falsenot(False)-> True。not (True and False)首先简化为not (False),然后进一步简化为True。
你应该看看德摩根定律,它(非正式地)指出:
"not (A and B)" 与 "(not A) or (not B)" 相同
此外,“非(A 或 B)”与“(非 A)和(非 B)”相同。
所以在你的情况下not(True and False)是not(True) or not(False)一样False or True的True
让我们一步一步来:
(True and False)评估为(False)
not (False)评估为True
很容易:)
按照运算顺序,先解括号里面的内容,用变量这样看:
a == True and False == False
not(True and False) == not(a) == not(False) == True
你当时想到的是:
not(True) and not(False)
这确实是错误的,因为:
a == not(True) == False
b == not(False) == True
not(True) and not(False) == a and b == False and True == False