I'm trying to make an example program in Python 2.7 which saves/shares states between two functions. You call a function, next time you call a function, it should remember the previous value. Here is my current code:
def stuff():
global x
x = 100
def f():
global x
x = x * 2
return x
def g():
global x
x = x * 4
return x
return (f, g)
a,b = stuff()
print(a());
This code works, BUT the catch is that x
must not be considered as a global variable outside the scope of stuff()
... (That is the whole point of embedding x within stuff()
in the first place). So, would x
be global, or is it local to stuff()
?