SyntaxError positional argument follows keyword argument

2.4k Views Asked by At

I am wondering if the below statement is correct.

SyntaxError: positional argument follows keyword argument

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

//It means that “A” comes after “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. 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:

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
1

There are 1 best solutions below

0
Michael Nikitin On

That's a feature of Python syntax. It interprets positional arguments in the order in which they appear first and then followed by the keyword arguments as next. 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' ". Because Python positionally interprets 10 and 20 as the first two variables, so 'a' and 'b' are already used