make_adder(x) that returns a new function which, when called with a single argument y, returns x + y. This is a lightweight form of currying: make_adder(5) should return a function equivalent to lambda y: 5 + y, but written as a nested def, not a lambda.add5 = make_adder(5) add5(3)
8
add5 closes over x=5, so calling it with 3 returns 5+3=8.
make_adder(10)(7)
17
The returned function can also be called immediately.
Define an inner function inside make_adder that references x from the enclosing scope.
Return the inner function itself (without calling it).