John,

Basically it's not evaluating it the way you think it is:

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.



On 4/26/06, John Connors <[EMAIL PROTECTED]> wrote:
G'day,

I found something today that has me confused. I'm making a list of 6 random
dice rolls and I want to check if any 1's or 5's were rolled. I tried this
way first and it returns true even if there are no 1's or 5's. I'll use a
roll of all 2's as an example.

rollList = [2,2,2,2,2,2]
if 1 or 5 in rollList:
   print 'yes'
else:
   print 'no'

Then I tried this and it works fine.

rollList = [2,2,2,2,2,2]
if 1 in rollList or 5 in rollList:
   print 'yes'
else:
   print 'no'

It doesn't really matter because the second way does what I want but I would
like to know why the first way doesn't work and if the syntax is wrong why
doesn't it return an error.

John

PS I apologise if this is a duplicate, hotmail did some kind of spam check
when I tried to send it, I've waited 30 mins and I don't think it went the
1st time so I'll post it again.

_________________________________________________________________
New year, new job – there's more than 100,00 jobs at SEEK
http://a.ninemsn.com.au/b.aspx?URL=""



_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor



_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to