proper loop syntax?

Jack Diederich jack at performancedrivers.com
Mon Aug 11 12:23:10 EDT 2003


On Mon, Aug 11, 2003 at 11:04:02AM -0500, JLowder at 360commerce.com wrote:
> Standard disclaimer here, I'm new to Python/Jython..
> 
> I have what should be a really simple for loop with nested if/elif's which 
> doesn't seem to function correctly. 
> 
>      elif y == "a" or "S":

is equivalent to:
  elif (y == "a"):
    # do stuff
  elif ("S"):
    # do stuff

try one of these instead

  elif y in ("a", "S"):
    # do stuff
  

  elif y in "aS": # shorter, but obscures the intent a little
    # do stuff


  elif (y == "a" or y == "S"):
    # do stuff


-jack





More information about the Python-list mailing list