Syntax for one-line "nonymous" functions in "declaration style"

Ian Kelly ian.g.kelly at gmail.com
Thu Mar 28 13:02:18 EDT 2019


On Wed, Mar 27, 2019 at 3:13 AM Paul Moore <p.f.moore at gmail.com> wrote:
>
> On Wed, 27 Mar 2019 at 08:25, Alexey Muranov <alexey.muranov at gmail.com>
wrote:
> >
> > 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
>
> Why? Is saving a few characters really that helpful? So much so that
> it's worth adding a *third* method of defining functions, which would
> need documenting, adding to training materials, etc, etc?

Well, it does seem a bit silly to have more ways of formatting strings than
of defining functions. We have four of the former, so clearly we need to
address this by adding two more of the latter.



More information about the Python-list mailing list