LoginSignup
0
0

More than 3 years have passed since last update.

【Udemy Python3入門+応用】 55. 関数内関数

Posted at

※この記事はUdemyの
現役シリコンバレーエンジニアが教えるPython3入門+応用+アメリカのシリコンバレー流コードスタイル
の講座を受講した上での、自分用の授業ノートです。
講師の酒井潤さんから許可をいただいた上で公開しています。

■関数内関数

◆使い方
inner_function
def outer(a, b):

    def plus(c, d):
        return c + d

    r = plus(a, b)
    print(r)

outer(1, 2)
result
3

関数の中で、さらに新しい関数を定義することも可能である。
内側の関数(plus)を、外側の関数(outer)以外の場所で使わない場合、
関数内関数として記述してやるとよい。

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