Boolean confusion

Frantisek Fuka fuka at fuxoft.cz
Fri Oct 31 14:37:29 EST 2003


John Roth wrote:

> "Frantisek Fuka" <fuka at fuxoft.cz> wrote in message
> news:bnua52$tnv$1 at ns.felk.cvut.cz...
> 
>>Can anyone please explain why these two give different results in Python
>>2.3?
>>
>> >>> 'a' in 'abc' == 1
>>False
>> >>> ('a' in 'abc') == 1
>>True
>>
>>I know it's not a good idea to compare boolean with Integer but that's
>>not the answer to my question.
> 
> 
> According to the operator precedence table given in the
> Python Reference Manual, section 5.14 (2.2.3 version)
> the "==" operator has higher precidence (that is, it will
> be evaluated first) than the "in" operator. The table is,
> unfortunately, upside down from my perspective, but
> a close examination of the explanation shows what is
> happening.
> 
> In other words, your first expression is equivalent
> to:
> 
> "a" in ("abc" == 1)

No, it is not, because the original expression produces "False" while 
your expression produces "TypeError: iterable argument required".

-- 
                                          Frantisek Fuka
(yes, that IS my real name)
(and it's pronounced "Fran-tjee-shek Foo-kah")
----------------------------------------------------
My E-mail:   fuka at fuxoft.cz
My Homepage: http://www.fuxoft.cz
My ICQ:      2745855





More information about the Python-list mailing list