1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?