[PYTHON] closure

closure.py


def outer(a, b):
    #Functions that can be used only within the function
    def inner(c):
        return a+b+c
    return inner
#At this point, the function has not been executed
f = outer(1, 2)
print(type(f))
print(f)
#()When passing an argument to an in-function function that is executed when is added, pass it at this time
r = f(3)
print(r)
<class 'function'>
<function outer.<locals>.inner at 0x112803290>
6

Recommended Posts

closure
Closure implementation
Python closure sample
Python> function> Closure
Image of closure
Low-pass filter using closure