[ZPT] If/else?

Guido van Rossum guido@digicool.com
Thu, 10 May 2001 11:42:31 -0400


> I'm a little unclear on cond().  For example, take 
> cond<expA, expB, expC).  Does it transmlate into
> 
> if (expA):
>    expB
> else:
>   expC

Sort-of.  What I had in mind was this:

  def cond(a, b, c=None):
    if a:
      return b
    else:
      return c

i.e. the three arguments are evaluated before testing (since this is
implemented as a regular function).  (Of course, Evan "bytecodehacks"
Simpson might have a different implementation in mind. :-)

> Or is it more akin to the "x|y|z" construct for path expressions,
> returning the first one that is defined and non-empty?

Hm, that should probably be a different function.

--Guido van Rossum (home page: http://www.python.org/~guido/)