Here there's two simple codes I don't understand.
def buggy(arg,result=[]):
result.append(arg)
print(result)
print('---')
buggy('a')
buggy('b')
buggy('c')
buggy('d')
output:
['a']
['a', 'b']
['a', 'b', 'c']
['a', 'b', 'c', 'd']
def buggy(arg,result=[]):
if len(result)==0:
result=[]
result.append(arg)
print(result)
print('---')
buggy('a')
buggy('b')
buggy('c')
buggy('d')
output:
['a']
['b']
['c']
['d']
I think if first code's output is True, the second code's output must to be the same as the first code's output. what happened?