Some syntactic sugar proposals

Steven D'Aprano steve-REMOVE-THIS at
Thu Nov 18 05:49:07 CET 2010

On Wed, 17 Nov 2010 16:31:40 +0000, Mark Wooding wrote:

> But I don't think that's the big problem with this proposal.  The real
> problem is that it completely changes the evaluation rule for the
> conditional expression.  (The evaluation rule is already pretty screwy:
> Python is consistently left-to-right -- except here.)

Not quite...

>>> 1+2*3
>>> (1+2)*3

But other than that, I agree with your analysis for why Python should not 
be changed to allow:

t = foo() as v if pred(v) else default_value

Not everything needs to be a one liner. If you need this, do it the old-
fashioned way:

t = foo()
if not pred(t): t = default_value


More information about the Python-list mailing list