What output would you expect for this python snippet?
def some_fn(arg=[]):
arg.append('value')
print(arg)
for i in range(5):
some_fn()
I would expect arg to be []
every time I call some_fn()
without arguments. As a matter of fact the instance of the default value is being kept.
Has my expectation just been wrong or is this a strange behavior in Python? At least in C++ default values are being assigned every time I call the function.