Is it really good?

Cliff Wells clifford.wells at attbi.com
Tue Jan 7 23:39:49 EST 2003


On Tue, 2003-01-07 at 17:19, Tim Peters wrote:
> [Skip Montanaro]
> >>     >>> 2 == 3 is good
> >> ...
> >> Chained operations.  The above expression is effectively
> >>
> >>     (2 == 3) and (3 is good)
> >
> 
> [Cliff Wells]
> > This confuses me.  What is the order of operation for '==' and 'is'?
> 
> Life will be simpler if you just believe Skip <wink>.  Just as
> 
>     1 <= i <= 10
> 
> *means*
> 
>     (1 <= i) and (i <= 10)
> 
> in Python, same thing if you substitute any other comparison operators for
> "<=".  "==" and "is" are two other comparison operators.

Ah, that clears it up.  I was having a blind spot.  It's still pretty
non-obvious though.


> > ...
> > How can (2 == 3) and (3 is good) be a possible equivalence?
> 
> The compiler goes out of its way to make it so, as it does for all chained
> comparisons.  See your friendly Language Reference Manual for details
> (although there's not more to it than what's already been said).

I don't think I've ever used chained comparisons aside from the
traditional a < b <= c type thing, so I guess I hadn't formed that small
part of the brain that generalizes them <wink>.

-- 
Cliff Wells <clifford.wells at attbi.com>






More information about the Python-list mailing list