강의

멘토링

로드맵

Inflearn Community Q&A

changsh20006121's profile image
changsh20006121

asked

Programming for Us: Intermediate Python (Inflearn Original)

First-class functions - Closures Advanced (3-2)

global 과 nonlocal의 차이점 질문

Written on

·

337

0

closure_ex2을 수업하던 중 global을 사용하면 되지 않나?라는 생각이 들어 global을 사용해봤는데 에러가 발생하는 것을 확인했고 closure_ex3에서 nonlocal을 사용하면 문제가 해결되더군요.

global로는 에러가 해결되지 않고 nonlocal로는 에러가 해결되는데 어떤 차이점 때문인걸까요?

djangopython

Answer 1

1

niceman님의 프로필 이미지
niceman
Instructor

스코프(scope)영역 차이입니다.

nonlocal , local , global 등의 실행 영역에 따라 

참조할 수 있는 영역이 있습니다.

강의 중에 자세하게 설명되니 반복해서 학습해 보세요.

changsh20006121's profile image
changsh20006121

asked

Ask a question