If - Or statements

Robert Kern rkern at ucsd.edu
Sat Jun 4 05:13:38 EDT 2005


Ognjen Bezanov wrote:
> Another newbie-ish question.
> 
> I want to create an if statement which will check if a particular
> variable matches one of the statements, and willl execute the statement
> if the variable matches any of the statements.
> 
> I have tried the following (the pass is just used for testing)
> 
> 
> if ext[1] == "mp3" or ext[1] == "mp4" or ext[1] == "ogg" or ext[1] ==
> "aac" or ext[1] != "wma":
>        print "we have a valid extension: " + ext[1] #here would go the
> code for decoding the above
>        pass

It works fine for me. Could you post the smallest complete program (one 
that defines ext) that displays the behavior and its entire output?

As an aside, is 'ext[1] != "wma"' correct or should it be ==? As 
written, you could collapse the whole thing to 'if ext[1] != "wma":' but 
I presume it is a typo.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Python-list mailing list