当调用这个函数时,我得到错误SyntaxError: keyword can't be an expression
def printAlbum(**albums):
for year in albums:
print year, albums[year]
printAlbum(2002='by the way', 1999='californication', 2006 = 'stadium arcadium')
用字母键调用函数没有问题。我尝试过在键周围加引号,并用:
替换=
,但这并没有解决问题。我能把数字键传给函数吗?在
Tags:
是非法语法,因为关键字必须是有效标识符。在
您必须重写
^{pr2}$printAlbum
以获得一个普通的dict
:注意,让关键字参数为的函数预期为的非标识符是一个坏主意,在这种情况下,永远不会有一种方法只使用关键字参数合法地调用函数。在
关键字args的键必须是有效的python标识符,例如不能以数字开头。在
相反,传递一个指令:
相关问题 更多 >
编程相关推荐