Operator Precedence/Boolean Logic

Jussi Piitulainen jussi.piitulainen at helsinki.fi
Wed Jun 22 03:14:51 EDT 2016


Christian Gollwitzer writes:

> Am 22.06.16 um 05:40 schrieb Elizabeth Weiss:
>> 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.
>>
>> I think the parenthesis are confusing me.
>
> Are you thinking, by any chance, that "or" indicates a choice?
> Comparing False to either False "or" True? That is not the case.
>
> "or" is an operator. "False or True" is *computed* and gives True,
> which is then compared to False by "==". Python works in these steps:
>
> 1) False ==  (False or True)
> 2) False ==  (True)
> 3) False

Similarly:

1) "coffee" == ("coffee" or "tea")
2) "coffee" == "coffee"
3) True

1) "tea" == ("coffee" or "tea")
2) "tea" == "coffee"
3) False

In programming languages that allow it, want("coffee" or "tea") is
probably not intended. One has to (want("coffee") or want("tea")).

I'm not trying to confuse. I'm trying to further illustrate how the
programming language notation differs from ordinary structures of
languages like English that may seem analogous until one learns that
they aren't, quite.



More information about the Python-list mailing list