single-line terinary operators considered harmful

Terry Reedy tjreedy at udel.edu
Wed Mar 5 13:52:46 EST 2003


"Clark C. Evans" <cce at clarkevans.com> wrote in message
news:mailman.1046884032.2904.python-list at python.org...
> Yes, but a conditional is unlike these binary operators,
> it has, to quote Dannis Reinhardt, a 'dangling else' ambiguity.

A true ternary C op a po b has no such ambiguity.  Every op must be
matched by a following po.   Every po matches the nearest preceding
unmatched op.  Just as with (), [], etc.  Possible ambiguity arises in
conditional statement trees because  'else: pass' is allowed to be
omitted.  But conditional expressions *must* evaluate to something in
all branched of the logic tree.

Terry J. Reedy






More information about the Python-list mailing list