Boolean confusion

John Roth newsgroups at jhrothjr.com
Fri Oct 31 14:57:43 EST 2003


"Alex Martelli" <aleax at aleax.it> wrote in message
news:p%yob.389675$R32.12897185 at news2.tin.it...
> John Roth wrote:
>    ...
> >>  >>> 'a' in 'abc' == 1
> >> False
>    ...
> > In other words, your first expression is equivalent
> > to:
> >
> > "a" in ("abc" == 1)
>
> Nope: that would raise an exception rather than returning
> False (try it!).
>
> What's happening is *chaining* of relationals, just like
> when you write e.g. a < b <= c.  In such cases the effect
> is line (a < b) and (b <= c) except that b is only evaluated
> once.  Similarly, the first expression above is equivalent
> to
>     ('a' in 'abc') and ('abc' == 1)

You're right. Section 5.9 says this, and directly contradicts
section 5.14 as well. 5.14 shows "in" as having a lower
priority than "==", while the verbiage n 5.9 says they
have the same priority.

One or the other should be corrected.

John Roth
>
>
> Alex
>






More information about the Python-list mailing list