Python 3.x SyntaxError:关键字不能是函数调用python3中的表达式
这是我为一个小型项目编写的代码,但我得到了这个错误 SyntaxError:关键字不能是表达式 请纠正它,我是一个新手,所以请解释迪利Python 3.x SyntaxError:关键字不能是函数调用python3中的表达式,python-3.x,function,dictionary,Python 3.x,Function,Dictionary,这是我为一个小型项目编写的代码,但我得到了这个错误 SyntaxError:关键字不能是表达式 请纠正它,我是一个新手,所以请解释迪利 谢谢大家! 关键字参数必须是标识符,而不是字符串: def orders(**sandwich): sand={} for category,toppings in sandwich.items(): sand[category]=toppings return sand orders('cheese'
谢谢大家! 关键字参数必须是标识符,而不是字符串:
def orders(**sandwich):
sand={}
for category,toppings in sandwich.items():
sand[category]=toppings
return sand
orders('cheese'='extra','toppings'='mushroom')
print(orders)
另外,请注意,您在循环的第一次迭代中返回了sand
此外,三明治已经是一种名言。实际上,您的功能可以替换为:
orders(cheese='extra', toppings='mushroom')
多谢各位
d = dict(cheese='extra', toppings='mushroom')
print(d)