[Tutor] Boolean question
Alan Gauld
alan.gauld at btinternet.com
Wed Mar 16 09:40:00 CET 2011
"Donald Bedsole" <drbedsole at gmail.com> wrote
> most part. But, could someone make sure I'm understanding this one
> expression correctly?
>
> not (False and True)
>
> Python evaluates it as "True"
>
> Is it because:
> 1)You evaluate what's in the parentheses first. A thing can not be
> false and true at the same time, so the answer is false.
> 2)However, the "not" outside the parentheses flips the meaning of
> what
> is inside the parentheses, so false becomes "True." ?
Absolutely correct. Well done.
Boolean algebra can be a weird thing to get your head around
the first time you come across it :-)
Here are some of the standard rules:
True and thing = thing
False and thing = False
True or thing = True
False or thing = thing
And perhaps most bizarre of all:
not(X or Y) = not X and not Y
not(X and Y) = not X or not Y
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list