SyntaxPython Error

SyntaxError

SyntaxError: positional argument follows keyword argument

Traceback

terminal
Traceback (most recent call last):
  File "main.py", line 1, in <module>
    print("hello", end=" ", "world")
SyntaxError: positional argument follows keyword argument

What causes this error

A positional argument was placed after a keyword argument in a function call. Python requires all positional arguments to precede keyword arguments.

How to fix it

Move positional arguments before all keyword arguments. Convert the positional argument to a keyword argument. Maintain consistent argument ordering in function calls.

Code that causes this error

Broken
print("hello", end=" ", "world")

Fixed code

Fixed
print("hello", "world", end=" ")

About SyntaxError

This SyntaxError is raised when positional arguments appear after keyword arguments in a function call. Python requires all positional arguments to come before keyword arguments in a call. This is a parsing-time error, meaning it is detected before any code runs.

The rule exists because once named arguments begin, there is no way to unambiguously assign positional arguments to parameters. This error commonly appears when reordering arguments and accidentally placing a positional one after named ones, or when adding new arguments to an existing call without maintaining the correct order. The fix is to either move the positional argument before all keyword arguments, or convert it to a keyword argument.

Common scenarios

1

Writing code with missing colons, parentheses, or brackets

2

Mixing Python 2 and Python 3 syntax when upgrading a codebase

3

Copy-pasting code from the web with formatting issues or invisible characters

4

Using reserved keywords as variable or function names

Related errors