我了解函数参数必须具有以下排序层次结构:
*args
**kwargs
我遇到此错误:
SyntaxError:关键字不能是表达式
在下面:
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')
我没有正确通过**kwargs
还是存在其他问题?
test_ = dfDiff(1, 2, city = 'Albany')
按照准则,关键字之间不能有等于和值的空格。
test_ = dfDiff(1, 2, city='Albany')