Search code examples
pythonbooleanboolean-algebra

Boolean Algebra - Why is not(True and False) True?


I'm doing the book "learn python the hard way". At exercise 27 (http://learnpythonthehardway.org/book/ex27.html) it starts with boolean algebra.

So my question is: why is not(True and False) True?

How I understood it, it should be the same thing as False and True.


Solution

  • Your interpretation is incorrect, see the De Morgan's laws; specifically the negation of a conjunction is the disjunction of the negations.

    not (True and False) (a negation of a conjunction == not(a and b)) is the equivalent of False or True (a disjunction of the negations == (not a) or (not b)); note the switch from and to or!

    You can also work out the steps:

    • not(True and False)
      • work out the part in parentheses first, True and False -> False
    • substitute that outcome back into the expression: not(False) -> True.