LoginSignup
1
3

More than 3 years have passed since last update.

クロージャ

Last updated at Posted at 2020-02-14
closure.py
def outer(a, b):
    #関数内だけで使える関数
    def inner(c):
        return a+b+c
    return inner
#この時点では、関数は実行されていない
f = outer(1, 2)
print(type(f))
print(f)
#()をつけると実行される、関数内関数に引数を渡す場合は、この時に渡す
r = f(3)
print(r)
<class 'function'>
<function outer.<locals>.inner at 0x112803290>
6
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3