Nested Scopes And Lambdas
def funct(): x = 4 action = (lambda n: x ** n) return action x = funct() print(x(2)) # prints 16 ... I don't quite understand why 2 is assigned to n automatically?
Solution 1:
n
is the argument of the anonymous function returned by funct
. An exactly equivalent defintion of funct
is
deffunct():
x = 4defaction(n):
return x ** n
return action
Does this form make any more sense?
Post a Comment for "Nested Scopes And Lambdas"