[Tutor] multiple if and or statement

Adam Bark adam.jtm30 at gmail.com
Mon Mar 14 20:54:54 CET 2011


On 14/03/11 19:41, Mike Franon 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?

Any string that isn't blank ie '' is true. In your test you've asked 
whether i == 'test1' is true or 'test2' is true not i == 'test2' is true.
I hope that's not too confusing, I can make it clearer if you're having 
a problem.

Adam.


More information about the Tutor mailing list