Good day, brilliant Stack Overflow Community. I noticed an interesting behavior regarding Python function when input as a dictionary.
When we use the empty list as a default argument, we can return that list while appending some value.
def func_list(value,input=[]):
return input.append(value)
I would expect the same thing to apply when empty dictionary as an argument. such as:
def func_dict(value,input={}):
return input[value] = value
However, Python will raise a Syntax Error, and I can only do something like:
def func_dict(value,input={}):
input[value] = value
return input
I am wondering why? Thank you so much!
PS. Please feel free to modify the question, and apologize if my expression of the question is not clear enough!