2 ms·
The problem is that the default argument is mutable. def f(a=[]): a.append('v') print a f(['ok']) # ['ok', 'v'] f() # ['v'] f() #
by saltylicorice 11y ago
The problem is that the default argument is mutable.
def f(a=[]):
a.append('v')
print a
f(['ok']) # ['ok', 'v']
f() # ['v']
f() # ['v', 'v']
- throwaway91919 11y agoAh, thanks.