[Python-Dev] Re: Trinary Operators (original) (raw)

Shane Holloway (IEEE) shane.holloway@ieee.org
Thu, 06 Feb 2003 18:09:07 -0700


Gerald S. Williams wrote:

Compare this to the order of evaluation in the current equivalent (parentheses for clarity only): (x and y) and 1 or 0

or if you prefer: ((x and y) and [1] or [0])[0]

I was thinking that the semantics of "and" & "or" are the replacement for the trinary operator? Since these operations always return the last evaluated subexpression (the same subexpression that short-circuits the evaluation), they can be used as Gerald outlines above. It seems very consistent, logical, and understandable to me; but then again, I love the semantics of list compressions. ;)

Thanks, -Shane Holloway