代码示例:(标识:python_ref_keyword_global)
python_ref_keyword_global.py
#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)
运行结果: