I\'m trying to add or subtract from a defined variable, but I can\'t figure out how to overwrite the old value with the new one.
a = 15
def test():
a =
Scope of the variable is local to the block unless defined explicitly using keyword global
. There is other way to access the global variable local to a function using globals
function
a = 15
def test():
a = globals()['a']
a += 10
print ( a )
test()
Above example will print 25
while keeping the global value intact i.e 15
.