Two questions on lambda:
kristian.zoerhoff at gmail.com
Fri Jun 24 09:09:26 EDT 2005
On 6/24/05, Xavier Décoret <Xavier.Decoret at imag.fr> wrote:
> For example, the code
> # f = lambda : print "hello"
> # f()
> does not compile, although:
> # def f():
> # print "hello"
> # f()
> does compile. Is there a particular syntax for lambda that I am missing
> or is it simply limited and I cannot do what I want with lambda.
lambda calls can only include functions; print is a statement, not a
function. Try this instead:
f = lambda : sys.stdout.writelines("Hello")
However, if you're going to be binding the function to a name, there
is no need to use lambda at all; just def a function and be done with
> In the same spirit, how can I do to compute intermediary values in the
> body of a lambda function. Let's say (dummy example):
I leave this to someone more expert than I.
More information about the Python-list