Syntax for one-line "nonymous" functions in "declaration style"
Alexey Muranov
alexey.muranov at gmail.com
Wed Mar 27 04:21:58 EDT 2019
Whey you need a simple function in Python, there is a choice between a
normal function declaration and an assignment of a anonymous function
(defined by a lambda-expression) to a variable:
def f(x): return x*x
or
f = lambda x: x*x
It would be however more convenient to be able to write instead just
f(x) = x*x
(like in Haskell and such).
Have this idea been discussed before?
I do not see any conflicts with the existing syntax. The following
would also work:
incrementer(m)(n) = n + m
instead of
incrementer = lambda m: lambda n: n + m
Alexey.
More information about the Python-list
mailing list