[Tutor] trouble with function-- trying to check

Isaac hyperneato at gmail.com
Wed Mar 14 09:04:28 CET 2007


As far as I can tell:
because (c in "crab") membership is in parentheses it is more binding than
the [==] comparison. That is why it returns true/false first.

I incorrectly wrote before:
" The [in] operator takes precedence"

http://docs.python.org/ref/summary.html


-Isaac


On 3/14/07, Isaac <hyperneato at gmail.com> wrote:
>
> a, b, c, or d is a type('str') not boolean which is what (c in "crab") is.
> The [in] operator takes presedence, the first 3 times (c in "crab") returns
> true and the last returns false; but the strings a, b, c, or d do not ==
> true or false - therefore the test (c == (c in "crab")) always returns
> false.
>
>
> (I think)
>
> cheers
>
> -Isaac
>
> reference:
> http://docs.python.org/ref/summary.html
>
>
> Terry wrote:
>
> >>> for c in "abcd":
> ...    print (c == c in "crab"), (c == (c in "crab"))
> ...
> True False
> True False
> True False
> False False
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070314/57309d83/attachment.htm 


More information about the Tutor mailing list