On Thu, Aug 1, 2013 at 4:29 PM, Terry Reedy <tjre...@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.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to