# Python CodeRecipe|nonlocalの使い方
❮ Home ❮ Python Keywords
# nonlocalの例1
Make a function inside a function, which uses the variable x as a non local
variable:
def myfunc1(): x = "John" def myfunc2():
nonlocal x x = "hello" myfunc2()
return xprint(myfunc1())
# nonlocalの定義及び使い方
nonlocal関数は、 ネストされた関数内の変数。 内部関数。 キーワードnonlocalを使用して、 変数がローカルではありません。
# nonlocalの例2
Same example as above, but without the nonlocal keyword:
def myfunc1(): x = "John" def myfunc2():
x = "hello" myfunc2() return xprint(myfunc1())
Related Pages The keyword global is used to make global variables.
❮ Home ❮ Python Keywords