-
Closure, First Class ObjectProgramming Language/Python 2024. 4. 11. 22:27
Nested function, Nonlocal, Global
Nested function Nested function(중첩 함수)는 함수 안에 함수를 가리킨다. 즉, 다음과 같은 형태로 함수를 정의한다면 def outer_function(a): x=0 def inner_function(b): y=1 inner_function(0) outer_function에 감싸진 inner_func
test22.tistory.com
이전에 중첩 함수에 대해 다뤘다.
이제 First Class Object(일급 객체)에 대한 개념을 배운다면 closure를 이해하고 사용할 수 있다. 이급 객체, 삼급 객체란 용어도 있으나 안 쓰인다고 한다.
초기에 일급 객체에 대한 정의로 다음 4가지를 만족해야 한다고 했으나
All items can be the actual parameters of functions. All items can be returned as results of functions. All items can be the subject of assignment statements. All items can be tested for equality.
현재에는 함수의 인자, 함수의 반환, 어떤 변수로 대입 등 이 3가지만 가능하기만 해도 일급 객체로 본다. 마지막 조건인 '동일 비교가 가능해야 한다'는 조건은 고려되지 않고 있다.
'Programming Language > Python' 카테고리의 다른 글
The Zen of Python (0) 2024.04.02 Nested function, Nonlocal, Global (0) 2024.04.02 Docstring (0) 2023.12.14 Boolean 더하기 (0) 2023.10.15 string 함수 split(), split(' ') 차이점 (0) 2023.10.13