[Tutor] multiple if and or statement

bob gailer bgailer at gmail.com
Mon Mar 14 21:53:59 CET 2011


On 3/14/2011 3:13 PM, Mike Franon wrote:
> Thank you everyone who responded, very fast responses I am impressed.
>
> OK now I see where I went wrong 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',

That is correct. Each iteration of the loop assigns one list element to a.

if (i == 'test1') or (i=='test2'): is one way to do what you want.

Another is if i in ('test1', 'test2'):

Instead of a tuple of values you could also provide a list, a set or a dictionary.

-- 
Bob Gailer
919-636-4239
Chapel Hill NC



More information about the Tutor mailing list