boolian logic
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Fri Jun 13 05:47:22 EDT 2008
En Fri, 13 Jun 2008 06:15:52 -0300, marc wyburn
<marc.wyburn at googlemail.com> escribió:
> HI all, I'm a bit stuck with how to work out boolian logic.
>
> I'd like to say if A is not equal to B, C or D:
> do something.
>
> I've tried
>
> if not var == A or B or C:
> and various permutations but can't seem to get my head around it. I'm
> pretty sure I need to know what is calulated first i.e the not or the
> 'OR/AND's
if A not in (B, C, D):
...
"or" has less priority than not, and all boolean operators have less
priority than comparisons. So your expression above reads as:
if (not (var==A)) or B or C
and the three or'ed expressions are evaluated from left to right
(short-circuit: stop as soon as any true value is found).
Evaluation order is defined in the Reference Manual, see
<http://docs.python.org/ref/expressions.html> in particular, operator
precedence is summarized in <http://docs.python.org/ref/summary.html>
--
Gabriel Genellina
More information about the Python-list
mailing list