Coming from a C/C++ background, I'm very unfamiliar with these rules in Python. If I create a new list in a python function, assign it as the member variable of some class, when the function ends, does the list go away? (In C/C++, the answer is yes unless there is some sort of dynamic allocation involved, but as I understand it, Python does it...automagically?)
Example:
class C:
def __init__(self, x):
self.val = x
self.l = []
class A:
def caller(self):
c_inst = someFunc()
print c_inst.l
def someFunc(self):
blah = C('name')
blah_l = [1,2,3,4,5]
blah.l = blah_l
return blah
What would be printed out inside the caller()
function? Would it be [1,2,3,4,5]
?