Reputation: 1097
I understand the function arguments must have the following ordering hierarchy:
*args
**kwargs
I'm getting this error:
SyntaxError: keyword can't be an expression
in the below:
def dfDiff(old, new, **kwargs):
# default dict of optional function arguments
d = {'city': 'Austin',
'capital': True,
'indx' : 5}
# if optional args are provided
if kwargs is not None:
# find the common keys
k_passed = kwargs.keys() & d.keys()
# change the default value
for k in k_passed:
d[k] = kwargs[k]
test_ = dfDiff(1, 2, 'city' = 'Albany')
did I pass **kwargs
incorrectly or there is some other issue?
Upvotes: 1
Views: 51
Reputation: 620
As @MichaelBianconi said in comments, while giving keyword-arguments, you need not enclosing them as strings. Just treat them like variables. So correct code is:
test_ = dfDiff(1, 2, city = 'Albany')
As per guidelines, don't have space between keyword, equal to and value.
test_ = dfDiff(1, 2, city='Albany')
Upvotes: 1