[Python-ideas] Leave off "else" in ternary expression
David Mertz
mertz at gnosis.cx
Fri Oct 28 12:20:58 EDT 2016
This seems pretty nonsensical to me. Ternaries are not only used in simple
assignments.
E.g. 'myfunc(a, b if pred else c, d)' is common and obvious.
'myfunc(a, b if pred, d)' is strange with no obvious semantics.
On Oct 28, 2016 11:29 AM, "Todd" <toddrjen at gmail.com> wrote:
> The null-coalescing discussion made me think about the current ternary "x
> = a if b else c" expression. In normal "if / else" clauses, the "else" is
> optional. I propose doing the same thing with ternary expressions
> (although I don't know what the result would be called, a "binary
> expression"?)
>
> The idea would be to allow this syntax:
>
> x = a if b
>
> Which would be equivalent to:
>
> x = a if b else x
>
> I think this would be useful syntax. In particular, I see it being useful
> for default value checking, but can also be used to override the result of
> particular corner cases from functions or methods..
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161028/879609ac/attachment.html>
More information about the Python-ideas
mailing list