[Python-ideas] Inline assignments using "given" clauses
steve at pearwood.info
Fri May 11 08:24:14 EDT 2018
On Fri, May 04, 2018 at 09:56:10PM -0400, Alexander Belopolsky wrote:
> This proposal has finally made me realize why I did not
> like PEP 572. The strong expression vs. statement dichotomy is one of
> the key features that set Python apart from many other languages and
> it makes Python programs much easier to understand.
I'm not so sure that the "expression versus statement" dichotomy is as
strong or as useful as Alexander says. If it were, we'd be writing much
more imperative code, as if it were 1970 and we were using BASIC.
Some of the greatest Python successes have been to add expression
forms of what used to be purely imperative statements:
- comprehensions (for-loops);
- ternary if (if...else statement).
In addition, we have more overlap between statements and expressions:
- an expression form of def (lambda);
- a functional form of the import statement (importlib.import_module,
before that people used to use __import__();
- expression forms of augmented assignment (ordinary + etc operators),
which is a rare case where the expression form came first and the
imperative command came afterwards.
I may have missed some.
Also notable is that Python does not have "procedures" (pure statement
callables). We use functions instead, and simply ignore the returned
If the difference between statements and expressions was really a
dichotomy, we would only need One Way to do these things, not two.
I also have seen many people disappointed that Python doesn't treat
"everything as an expression". The lack of assignment-expressions is a
turn-off for some people:
More information about the Python-ideas