Python globalキーワード
例
関数内でグローバル変数を宣言し、関数外で使用します。
#create a function:
def myfunction():
global x
x =
"hello"
#execute the function:
myfunction()
#x should now
be global, and accessible in the global scope.
print(x)
定義と使用法
キーワードは、global
関数内など、非グローバルスコープからグローバル変数を作成するために使用されます。