[Tutor] Checking in lists

Kent Johnson kent37 at tds.net
Wed Apr 26 16:05:49 CEST 2006


Jason Massey wrote:
> John,
> 
> Basically it's not evaluating it the way you think it is:

Right.
> 
> Your first example really equates to:
> 
> if (1 or 5) in rollList:
>    etc...
> 
> (1 or 5) equals 1  and 1 isn't in the your list.

Not quite. It's
   if 1 or (5 in rollList):

Since 1 evaluates to true, the result will always be 1.

Operator precedence is summarized here:
http://docs.python.org/ref/summary.html

Kent



More information about the Tutor mailing list