更新时间:2022-04-16 03:53:17
如注释中所述,Python中的 global
表示模块级别.
As stated in the comments, global
in Python means module level.
这样做:
a = 1
对 a
的作用与以下完全相同:
Has the exact same effect on a
as:
def f():
global a
a = 1
f()
在这两种情况下,变量都不在模块之间共享.
And in both cases the variable is not shared across modules.
如果要在模块之间共享变量,请检查此.
If you want to share a variable across modules, check this.