파이썬의 First-Citizen(일급시민), Closure, Decorator
1. First-Citizen 정의 : First-Citizen은 특정 자료형을 의미하는 것이 아니고 위 3가지 조건을 만족하면 First-Citizen이다. First-Citizen의 조건 - 변수나 데이터에 할당할 수 있다. - 객체의 인자로 전달할 수 있다. - 객체의 리턴값으로 리턴할 수 있다. function_name / function_name() 에 대한 차이를 먼저 알아야 함. 파이썬에서는 함수도 일급시민이 될 수 있다. 예를들어 아래 코드를 보자. def some_func(number): def square(): print(number * number) return square some_func(4)를 호출하면 square 함수를 반환한다. square 함수의 실행 결과값이 아니라 함수를 반환한다. 2. Closure (먼저 일급시민에 대한 이해가 필요하다) 정의 : 외부 함수의 실행이 종료된 후에도, 내부 함수가 local scope내의 변수(외부함수에서 정해진 변수라던가)를 기억하고 접근할 수 있는 경우를 의미. * 쉽게 말해 외부함수에 의해 환경이 설정 된 내부 함수를 의미한다. Closure is an inner function that remembers and has access to variables in the local scope in which it was created even after the outer function has finished executing. Closure closes over the free variables from their environment. 예를들어, 아래와 같은 함수가 있을 때 def outer_func(msg): message = msg def inner_func(): print(message) return inner_func hi_func = outer_func("Hi") hello_func = outer_...