Python Global Keyword Behavior
I am trying to use a global variable across modules by importing the variable and modifying it locally within a function. The code and the output is below. The last output is not w
Solution 1:
As stated in the comments, global
in Python means module level.
So doing:
a = 1
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.
Post a Comment for "Python Global Keyword Behavior"