Suppose I have a global variable a. And within a function definition, we also have a local variable named a. Is there any way to assign the value of the global variable to that of the local variable?
a = 'foo'
def my_func(a = 'bar'):
# how to set global a to value of the local a?
Use built-in function
globals().BTW, it’s worth mentioning that a global is only “global” within the scope of a module.