On Mon, Mar 14, 2011 at 12:41 PM, Mike Franon <kongfra...@gmail.com> wrote:

> HI,
>
> I had a question, when running this small snippet of test code:
>
>
>
> a = ['test1', 'flag', 'monday']
>
> for i in a:
>    if i == 'test1' or 'test2':
>       print 'true'
>
>
> It always prints true
>
>
> $ ./testing.py
> true
> true
> true
>
>
> I know I am missing something, but in reality it should only print
> true once correct?
>
> No.  The string 'test2' (actually, ALL non-empty strings) evaluates to
True, so your condition will always be met.
Try this:

> if (i == 'test1') or (i == 'test2'):
>

or:

> if i in ('test1', 'test2'):
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to