[Tutor] trouble with function-- trying to check

Kent Johnson kent37 at tds.net
Wed Mar 14 11:39:01 CET 2007


Terry Carroll wrote:
> On Wed, 14 Mar 2007, Isaac 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.
> 
> The thing is, if the in operator takes precedence than why do 
> 
> 
>   (c == c in "crab")
> 
>  and 
> 
>   (c == (c in "crab"))
> 
> return different results?

This has already been discussed on this thread. == and 'in' are comparisons.
(c == c in 'crab')
means
(c == c) and (c in 'crab')

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

Kent


More information about the Tutor mailing list