SyntaxError: positional argument follows keyword argument
时间: 2023-12-08 12:58:58 浏览: 139
解决pip install xxx报错SyntaxError: invalid syntax的问题
4星 · 用户满意度95%
This error occurs when a positional argument is passed after a keyword argument in a function call.
For example:
```
def my_function(a, b, c):
print(a, b, c)
my_function(a=1, 2, c=3)
```
In the above example, the function `my_function` expects three positional arguments `a`, `b`, and `c`. However, in the function call, we have passed `a` as a keyword argument and `2` as a positional argument. This will result in a `SyntaxError: positional argument follows keyword argument` error.
To fix this error, we need to either pass all the arguments as positional or all as keyword arguments.
For example:
```
my_function(1, b=2, c=3)
```
In the above example, we have passed all the arguments as keyword arguments, so there won't be any syntax error.
阅读全文