본문 바로가기

컴퓨터

Python에서 함수 호출 시 소괄호가 두 번 나오는 것이 무엇인가?

python에선 some_function(a,b)(x)처럼 소괄호가 두번 나오는 것이 있다. 처음보면 함수포인터랑 비슷하게 생겼는데 잘 모르겠는 무언가일 것이다. some_function의 내부를 뜯어보면 답이 나온다.

def some_function(a, b):
    def another_function(x):
        print(a+b+x)
    return another_function

some_function은 함수를 리턴하고 따라서 리턴한 함수에 x라는 값을 준 것이다.