You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

疑问:SyntaxError提示‘positional argument follows keyword argument’是否准确

关于Python语法错误提示‘SyntaxError: positional argument follows keyword argument’的困惑

我清楚位置参数(positional argument)和关键字参数(keyword argument)的概念,也知道函数调用时应该先传递位置参数,再传递关键字参数。但我对报错提示‘SyntaxError: positional argument follows keyword argument’感到困惑——按照“A follows B”表示“A在B之后”的逻辑,正确的提示似乎应该是‘SyntaxError: keyword argument follows positional argument’才对?

示例1:错误调用触发报错

def test(a,b,c):
    print(f"Sum of all no is : {a+b+c}")
test(a=10,20,c=30)
test(a=10,20,c=30)
//output                   ^
SyntaxError: positional argument follows keyword argument

这个示例中,因为先传递了关键字参数a=10,再传递位置参数20,触发了上述语法错误提示。

示例2:正确调用执行正常

# Passing positional argument first.
def test(a,b,c):
    print(f"Sum of all no is : {a+b+c}")
test(20,c=10,b=30)
//output
Sum of all no is : 60

先传递位置参数20,再传递关键字参数,函数就能正常执行并输出结果。

内容的提问来源于stack exchange,提问作者Shailesh Yadav

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 10:18:19