single-line terinary operators considered harmful

Lennart Regebro lennart at
Wed Mar 5 15:18:10 CET 2003

"Clark C. Evans" <cce at> wrote in message news:<mailman.1046832150.1332.python-list at>...
> Getting it to fit on a single line is just an unnecessary
> distraction, and, IMHO, one that is bogging down the whole 
> discussion down... and preventing a good mechanism to 
> express conditional logic within an expression.


That said, I don't mind a x = conditional(c, a, b), becuase it looks
like a function. If people neseecarily have to make if-then-else
statements like this on one line, create that function. Heck, here it

def conditional(c, a, b):
    if c:
        return a
        return b


Look, I even tested it for you! :)

>>> from conditional import conditional
>>> x = conditional(1, 'True', 'False')
>>> print x

So there. No, go and vote "I reject all options". There is no point in
adding ugluness to a pretty language if that uglyness doesn't have a
real value, and this hasn't. If you want one line conditionals, now
you have them. :)

More information about the Python-list mailing list