Python 09 Nested Function, Closure, Decorator
3193 ワード
ネスト機能
1.概念
オーバーラップ関数は
第
関数自体ではなく内部関数の戻り値を返す関数は、ネスト関数
2.理解
変形例
1
def parent_function():
def child_function():
return "this is a child function"
return child_function 🔴
print(parent_function())
# <function parent_function.<locals>.child_function at 0x7feb10b2bee0>
2
def parent_function():
def child_function():
return "this is a child function"
child_function() 🔴
print(parent_function())
# None
義父関数の戻り値が未定なので
3
def parent_function():
def child_function():
print("this is a child function") 🔵
child_function() 🔴
print(parent_function())
# this is a child function 🔵
# None 🔴
レプリカ
1.使用理由
2.概念
3.理解
#클로저
def outer(num):
def inner():
return num + 3
return inner
print(outer(10))
# <function outer.<locals>.inner at 0x01FDC340>
#cf)nested function
def outer(num):
def inner():
return num + 3
return inner()
print(outer(10))
# 13
デコレーション🏼
@is_paid_user
def jackpot_stock_information():
return "계시가 내려졌습니다. 삼성전자를 사세요!"
Reference
この問題について(Python 09 Nested Function, Closure, Decorator), 我々は、より多くの情報をここで見つけました https://velog.io/@maxkmh/Python-09-Nested-Function-Closure-Decoratorテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol