0

Start with example,

def foo(inp, out=[]):
    out.append(inp)
    return out

if __name__=='__main__':
    print foo('asd') #return ['asd']
    print foo('bsd') #return ['asd', 'bsd']

I expect out is defined within the scope of function foo and would not pass to next call of the function. But as you can see after calling foo('asd'), calling foo('bsd') will have the memory of its previous call, returing ['asd', 'bsd']. And I can't find out is saved in my python runtime. it is somehow stored invisibly.

Anyone has idead?

Ken T
  • 2,255
  • 1
  • 23
  • 30

0 Answers0