0
2

More than 3 years have passed since last update.

クロージャー 関数に引数を入れて後で実行したい場合

Last updated at Posted at 2020-01-10
def outer(a, b):

    def inner():
        return a + b

    return inner# inner関数を呼び出すのではなくオブジェクトを返す

f = outer(1,3)
print(f)
print(f())
実行結果
<function outer.<locals>.inner at 0x7**c3dfa*****>
4

print(f)では
innerオブジェクトの情報が返ってきて、
a + bは実行されていない。

f()とするとinnnerが実行される。

0
2
1

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
0
2