Proposed PEP for a Conditional Expression
markus at schabi.de
Mon Sep 17 17:01:29 CEST 2001
Michael Chermside <mcherm at destiny.com> schrub:
> def f(a,b=1):
> x = a > 0: return a else return b
> return x ** 2 - 1
> Apparently Markus's syntax implies that after a colon appearing in a
> statement (as opposed to other, normal :'s in Python), the "return"
> keyword no longer means to return from a function.
Yes, but I wanted to always have brackets "()" around it (just as we
have the  around the list comprehension)
x = (a > 0: return a else return b)
Currently, return and : both can't appear inside of (), and so it
should be clear which return is meant.
> Markus... did I mis-interpret? Do you still think this is a useful
My objection to this would be that it is too much to type, and that's
why I made a second proposal some lines later.
I'm rather shure that it is impossible to invent conditional expressios
without redefining something or inventing new keywoards or symbols.
And in my case I define new meanings for :, else and (in the first
proposal) return in a context where they are illegal now, so it
shouldn't break any existing code.
"The strength of the Constitution lies entirely in the determination of
each citizen to defend it. Only if every single citizen feels duty
bound to do his share in this defense are the constitutional rights
secure." -- Albert Einstein
More information about the Python-list