Boolean confusion
John Roth
newsgroups at jhrothjr.com
Fri Oct 31 14:19:26 EST 2003
More information about the Python-list mailing list
Fri Oct 31 14:19:26 EST 2003
- Previous message (by thread): Boolean confusion
- Next message (by thread): Boolean confusion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"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) John Roth > > -- > 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 >
- Previous message (by thread): Boolean confusion
- Next message (by thread): Boolean confusion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list