Use lambda to define inner function : Function Inner « Function « Python






Use lambda to define inner function

Use lambda to define inner function

def func():
    x = 4
    action = (lambda n: x ** n)          # x in enclosing def
    return action

x = func()
print x(2) # prints 16

           
       








Related examples in the same category

1.Inner function definitionInner function definition
2.Define and call a function inside another functionDefine and call a function inside another function
3.Nested function: 3 levelsNested function: 3 levels