[Python-Dev] Re: Trinary Operators

Guido van Rossum guido@python.org
Thu, 06 Feb 2003 15:01:43 -0500


> As long as you wait until April 1 (that's an odd day).

:-)

> I'm an even-day fan of trinary operators myself, but
> this opens too many questions. For example, with
> regard to short-circuiting, it will be inconsistent
> with other expressions at some level in either form
> or function.

How so?  If we give 'or' (and hence 'and') a higher priority --
i.e. binding tighter -- than 'if' and 'else', it's unambiguous to the
parser and also consistent with the if statement:

  if x and y:
     print 1
  else
     print 0

means the same as

  print 1 if x and y else 0

This is also similar to how lambda groups relative to and/or (and/or
has a higher priority).

I'm not sure yet how lambda and if/else should group relative to each
other.

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