def foo1(x, item=[]):
item.append(x)
return item
def foo2(x, item=None):
if item is None:
item = []
item.append(x)
return item
print(foo1(1))
print(foo2(2))
item = []
print(foo1(3, item))
print(foo1(4, item))
输出:
[1]
[2]
[3]
[3, 4]