[Tutor] Boolean question

Jack Trades jacktradespublic at gmail.com
Wed Mar 16 06:55:19 CET 2011

On Wed, Mar 16, 2011 at 12:22 AM, Donald Bedsole <drbedsole at gmail.com>wrote:

> 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.

Yes, the expression in the parenthesis is evaluated first.  However it's not
just one thing being evaluated.

'and' evaluates one argument at a time and returns immediately if the
argument is False.

In this case there are 2 distinct 'things'.  False and True.  False,
obviously, evaluates to False, which causes 'and' to stop and return False.
This reduces the expression to...

not False

> 2)However, the "not" outside the parentheses flips the meaning of what
> is inside the parentheses, so false becomes "True." ?

Correct, the expression "not False" evaluates to True.

Jack Trades
Pointless Programming Blog <http://pointlessprogramming.wordpress.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110316/a81c8fa6/attachment.html>

More information about the Tutor mailing list