[Python-Dev] PEP 8 modernisation

Alexander Belopolsky alexander.belopolsky at gmail.com
Thu Aug 1 22:52:19 CEST 2013


On Thu, Aug 1, 2013 at 4:29 PM, Terry Reedy <tjreedy at udel.edu> wrote:

> def f(x): return 2*x
> f = lambda x: 2*x
>

Am I the only one who finds the second line above much more readable than
the first?  The def statement is not intended to be written in one line.
 The readability suffers because the argument is separated from the value
expression by return keyword.

When def statement is written traditionally:

def f(x):
    return 2*x

It is easy to run the eyes over the right margin and recognize a function
that in a math paper would be written as "f: x -> 2 x".  Same is true about
lambda expression.  While C# syntax "f = (x => 2*x)" is probably closest to
mathematical notation, "f = lambda x: 2*x" is close enough.  One can
mentally focus on the "x: 2*x" part and ignore the rest.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130801/bad11c3a/attachment.html>


More information about the Python-Dev mailing list