Operator Precedence/Boolean Logic

Ben Finney ben+python at benfinney.id.au
Tue Jun 21 23:59:10 EDT 2016


Elizabeth Weiss <cake240 at gmail.com> writes:

> Hi There, 

Welcome! Your questions are fine here, but you may like to know that we
also have a beginner-specific forum for collaborative tutoring
<URL:https://mail.python.org/mailman/listinfo/tutor>.

> I am a little confused as to how this is False:
> False==(False or True)
>
> I would think it is True because False==False is true.

What does ‘(False or True)’ evaluate to, when you try it in the REPL?

> I think the parenthesis are confusing me. 
> (False==False) or True
>
> This is True. Is it because False==False? And True==False is not True
> but that does not change that this is True. 

Heh. You express the confusion quite well :-)

Try the component expressions in the REPL (the interactive interpreter
session) and see if that helps::

    >>> False or True
    …
    >>> (False or True)
    …
    >>> True == False
    …
    >>> (True == False)
    …
    >>> False == False
    …
    >>> (False == False)
    …

Then, once you think you understand what those expressions evaluate to,
look again at how those results would work in a more complex
expression::

    >>> False == (False or True)
    …
    >>> (False == False) or True
    …

> Thank you for your help!

I hope that helps.

-- 
 \     “[W]e are still the first generation of users, and for all that |
  `\      we may have invented the net, we still don't really get it.” |
_o__)                                                   —Douglas Adams |
Ben Finney




More information about the Python-list mailing list