I have two questions about this code:
def a_funcs():
class A:
def __init__(self):
self.a = 0
a_local = A()
def set_a(a):
a_local.a = a
def get_a():
return a_local.a
return set_a, get_a
set_a, get_a = a_funcs()
print(get_a())
set_a(17)
print(get_a())
Does a_local
keep existing after a_funcs
have been returned? Is it still in the scope of a_funcs
? Can it happen that the garbage collector deletes a_local
?
Where is a_local
stored technically? On the stack or on the heap?