Python/ref keyword global
来自菜鸟教程
<languages />
Python全局关键字
例
在函数内部声明一个全局变量,并在函数外部使用它:
#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)
定义和用法
The
global
关键字用于从非全局范围创建全局变量,例如在函数内部。