python - function scope

LEGB order: look inside out

local: local scope

enclosing: the local scope of the nested parent

global: global scope

build_in: built-in function scope

 

The variable declared with the global keyword must be in the global scope, not in the nested scope. When you want to modify the variables in the nested parent scope (enclosing scope, outer non-global scope), the nonlocal keyword is required.

The nonlocal keyword is a new keyword in python3.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325303603&siteId=291194637