Lamdba forms

L

lsmith234

hi all, I am a python newbie. why functions created with lambda forms
cannot contain statements?
how to get unnamed function with statements?
 
T

Terry Reedy

hi all, I am a python newbie. why functions created with lambda forms
cannot contain statements?

Because statement do not fit in expressions.
how to get unnamed function with statements?

Can't.

Many discussions in archives (which Google has).

tjr
 
P

Paddy

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.

- Cheers, Paddy.
 
A

Ant

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_function = inner
my_local_function(3,4)

outerfn()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top