Skip to main content
Skip table of contents

스코핑 룰

기능

  • 함수내에 지역변수에 해당하는 이름의 값이 없을 경우 LGB 규칙에 기반하여 이름을 찾을 수 있습니다.

    • 이름공간 : 변수의 이름이 저장되어 있는 장소

    • Local scope : 함수 내부의 이름 공간, 지역 영역

    • Global scope : 함수 밖의 영역, 전역 영역

    • Built-in scope : 파이썬 자체에서 정의한 내용에 대한 영역, 내장 영역

    • LGB 규칙: 변수 이름을 찾는 순서 local → global → built-in

예제

PY
# Error: can't find simple_pi in circle_area
simple_pi = 3.14
def circle_area(r):
return r*r*simple_pi

# simple_pi should be declared as global if it is used in circle_area_ok
def circle_area_ok(r):
global simple_pi
return r*r*simple_pi

tp_log(str(circle_area(3.0)))
#expected result: 28.26

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.