<lsmith234@gmai l.com> wrote in message
news:1145492986 .738200.229690@ i39g2000cwa.goo glegroups.com.. .[color=blue]
> hi all, I am a python newbie. why functions created with lambda forms
> cannot contain statements?[/color]
Because statement do not fit in expressions.
[color=blue]
> how to get unnamed function with statements?[/color]
To expand on the above, Python does not have statements in its lambda
forms, but that does not stop pythoneers from getting the job done.
I use a named function for that, but if you have an issue with that, it
really is worth following Terry's advice as the subject has been
tackled at great length before.
Why does the function have to be unnamed? you can easly nest function
definitions and refer to them. IIRC the lambda form is probably going
to be removed at some point, as it is not needed:
def outerfn():
dostuff()
def inner(x,y):
out = (x^y)
print out
return out
my_local_functi on = inner
my_local_functi on(3,4)
(one would have thought that someone might have added a note to
the comments of the first post, but the most recent contributor to
that thread is a mortgage spammer...)
This PEP, previously known as PEP 3000, describes smaller scale changes and new features for which no separate PEP is written yet, all targeted for Python 3000.
In particular:
"Lambdas will have to be parenthesized [23]"
Ant wrote:
[color=blue]
> Fair enough. I've just found this as well, which implies that lambda
> isn't being killed off in 3.0:
>
> http://www.python.org/dev/peps/pep-3100/
>
> In particular:
> "Lambdas will have to be parenthesized [23]"
>[/color]
Comment