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

Antoon Pardon antoon.pardon at vub.be
Wed Mar 27 11:41:42 EDT 2019


On 27/03/19 09:21, Alexey Muranov 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
>
> (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:

I don't know. Something like the following is already legal:

f(x)[n] = x * n

And it does something completly different.

-- 
Antoon Pardon.




More information about the Python-list mailing list