代码示例:(标识:python_variables_global_4)
python_variables_global_4.py
x = "awesome"

def myfunc():
  global x
  x = "fantastic"

myfunc()

print("Python is " + x)
运行结果: