1. ホーム 
  2. 備忘録 
  3. Python

関数内関数

関数内関数

ある関数の中で、外部からは必要としないが内部で繰り返す必要のある処理がある場合に関数内関数を使用することができる

関数内関数の書き方について以下に記載する


### 関数内関数の使い方
def outer(a, b):
    def inner(c, d):
        return c * d // c

    r1 = inner(a, b)
    r2 = inner(b, a)
    print(r1 + r2)  # 3


outer(1, 2)  # 3