简体   繁体   English

SyntaxError:位置参数跟随关键字参数

[英]SyntaxError: positional argument follows keyword argument

I am wondering if the below statement is correct.我想知道下面的说法是否正确。

SyntaxError: positional argument follows keyword argument SyntaxError:位置参数跟随关键字参数

I know what is positional argument and keyword argument but getting confused with the above statement.我知道什么是位置参数和关键字参数,但对上述语句感到困惑。 for example when we say例如当我们说

A follows B It means A 跟随 B 这意味着

//It means that “A” comes after “B” //这意味着“A”在“B”之后

So in the same way when we are calling any function then we should pass the positional argument first and then the keyword argument.因此,以同样的方式,当我们调用任何 function 时,我们应该先传递位置参数,然后传递关键字参数。 And in that case, correct statement should be在这种情况下,正确的陈述应该是

***SyntaxError: keyword argument follows positional argument***

example:例子:

    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

example2:示例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

That's a feature of Python syntax.这是 Python 语法的一个特点。 It interprets positional arguments in the order in which they appear first and then followed by the keyword arguments as next.它按照它们首先出现的顺序解释位置 arguments,然后是关键字 arguments 作为下一个。 For example this code:例如这段代码:

def test(a,b,c):
    print(f"Sum of all no is : {a+b+c}")
test(10,20,a=30)

Returns "TypeError: test() got multiple values for argument 'a' ".返回“TypeError: test() got multiple values for argument 'a'”。 Because Python positionally interprets 10 and 20 as the first two variables, so 'a' and 'b' are already used因为 Python 在位置上将 10 和 20 解释为前两个变量,所以 'a' 和 'b' 已经使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 语法错误:位置参数跟随关键字参数 [discord.py] - SyntaxError: positional argument follows keyword argument [discord.py] 对networkx失败:SyntaxError:关键字关键字后跟位置参数 - failed to networkx: SyntaxError: positional argument follows keyword argument 我该如何解决 SyntaxError:位置参数跟随关键字参数 - How can I slove SyntaxError: positional argument follows keyword argument 未能更正:此错误 SyntaxError:位置参数跟随关键字参数 - failed to correct : this error SyntaxError: positional argument follows keyword argument SyntaxError:位置参数遵循 CNN model 中的关键字参数 - SyntaxError: positional argument follows keyword argument in CNN model 语法错误:位置参数跟在关键字参数之后。 如何绕过它? - SyntaxError: positional argument follows keyword argument. How to bypass it? Python celery任务画布:SyntaxError:位置参数紧跟关键字参数 - Python celery task canvas: SyntaxError: positional argument follows keyword argument Dash_table:SyntaxError:位置参数跟随关键字参数 - Dash_table: SyntaxError: positional argument follows keyword argument PYTHON中的错误位置参数跟随关键字参数 - ERROR IN PYTHON Positional argument follows keyword argument 语法错误:位置参数跟随关键字参数: - Syntax Error: positional argument follows keyword argument:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM