📜  如何在函数python代码示例中访问全局变量

📅  最后修改于: 2022-03-11 14:45:04.834000             🧑  作者: Mango

代码示例1
#A global variable can be accessed from any function or method.
#However, we must declare that we are using the global version and not the local one.
#To do this, at the start of your function/method write "global" and then the name of the variable.
#Example:
myVariable = 1

def myFunction():
  global myVariable
  print(myVariable)

myFunction()