def test_func(x, l=[]):
l.append(x)
return l
r = test_func(100)
print(r)
r = test_func(100)
print(r)
I should have made an empty list as the default argument ...
[100]
[100, 100]
def test_func(x, l=None):
if l is None:
l = []
l.append(x)
return l
r = test_func(100)
print(r)
r = test_func(100)
print(r)
output:
[100]
[100]
Recommended Posts