python: global v.s. nonlocal

  • Nonlocal
    Nonlocal is similar in meaning to global. But it takes effect primarily in nested methods. It means "not a global or local variable." So it changes the identifier to refer to an enclosing method's variable.

相关栗子阅读:

  • global, nonlocal
  • stackoverflow 上的问题: Python nonlocal statement

read more

PEP 3104 -- Access to Names in Outer Scopes

你可能感兴趣的:(python: global v.s. nonlocal)