[Tutor] multiple if and or statement

Emile van Sebille emile at fenx.com
Mon Mar 14 21:32:01 CET 2011


On 3/14/2011 1:13 PM Mike Franon said...
> Thank you everyone who responded, very fast responses I am impressed.
>
> OK now I see where I went wrong

Well, no, I don't think so.  Your first test was:

if i=='test1' or 'test2':


which evaluates as true if _either_ i=='test1'  _or_ 'test2'

so, the first test is i=='test1'  and the second test if simply 'test2'.

Try the following:

if 'test2': print "non-empty strings evaluate as true"

if not "": print "the not of an empty string evaluates true"

HTH,

Emile




> and had to do
>
>
> if (i == 'test1') or (i=='test2'):
>
>
> I guess I was thinking if I do
>
>
> a = ['test1', 'flag', 'monday']
> for i in a:
>
> It would check each item in the list one at a time like a loop I was
> thinking, so the first time it would test for 'test1', and the second
> time it would test for 'flag', did not realize it would test the
> entire list all at once.



More information about the Tutor mailing list