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