Skip to content

Instantly share code, notes, and snippets.

@nattybear
Last active November 13, 2020 14:40
Show Gist options
  • Save nattybear/7aaabdc63dc9c71d70f6253dea223bb2 to your computer and use it in GitHub Desktop.
Save nattybear/7aaabdc63dc9c71d70f6253dea223bb2 to your computer and use it in GitHub Desktop.
파이썬 자유 변수 Python Free Variable

자유 변수

위키백과에 따르면 프로그래밍 용어 중 자유 변수 free variable 의 의미는 아래와 같다.

In computer programming, the term free variable refers to variables used in a function that are neither local variables nor parameters of that function. The term non-local variable is often a synonym in this context.

파이썬 문서에서 자유 변수의 정의는 아래와 같다.

If a variable is used in a code block but not defined there, it is a free variable.

그러니까 정확하지는 않지만 지역 변수가 아니면 자유 변수인 것 같다.

예를 들어 아래 코드에서 변수 free는 함수 inside의 입장에서는 지역 변수가 아니므로 자유 변수이다.

def outside():
  free = 1
  def inside():
    print(free)

자유 변수를 알면 클로저나 데코레이터를 다루는데 도움이 될 수 있다.

대문 링크

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment