How to fix SyntaxError: non-default argument follows default argument in Python

PythonBEGINNERLOWUpdated Dec 7, 2025ยท 161 views

SyntaxError means your Python code has invalid syntax that violates Python's grammar rules. The error message usually points near the problem. Common issues are missing colons, incorrect indentation, or mismatched parentheses.

Quick fix

Fixes SyntaxError: non-default argument follows default argument

File "script.py", line 42
  if x > 5  # Missing colon!
        ^
SyntaxError: invalid syntax
  1. Check the error line and surrounding lines
  2. Verify Python 3 syntax
  3. Check indentation
  4. Match parentheses and quotes
python โ€” error
File "script.py", line 42
if x > 5 # Missing colon!
^
SyntaxError: invalid syntax
SyntaxError: non-default argument follows default argument

What this error means

The "SyntaxError" error means Python's parser found code that doesn't follow Python's syntax rules. Unlike runtime errors, this happens before code even runs. Common causes: 1. **Missing colons**: if/for/while/def/class statements need a colon at the end 2. **Indentation errors**: Python requires consistent indentation 3. **Mismatched brackets**: Parentheses, brackets, or quotes not balanced 4. **Wrong syntax**: Using Python 2 syntax in Python 3 or vice versa 5. **Special characters**: Invalid encoding or non-ASCII characters Python will refuse to run the file until syntax is fixed.

Typical symptoms

  • SyntaxError: invalid syntax
  • Code won't even start running
  • Error points to a line that looks correct

Common causes

  1. Missing colon after if/for/while/def statements
  2. Indentation error
  3. Mismatched parentheses, brackets, or quotes
  4. Using Python 2 syntax in Python 3 or vice versa
  5. Invalid characters or encoding issues

How to fix "SyntaxError: non-default argument follows default argument"

1Check the error line and surrounding lines

Look at the traceback - the error is usually near the reported line:

bash
File "script.py", line 42
  if x > 5  # Missing colon!
        ^
SyntaxError: invalid syntax

Check the line above too, as the real error might be there.

2Verify Python 3 syntax

Common Python 2 vs 3 issues:

python
# Python 2 (wrong in Python 3)
print "Hello"  # Missing parentheses
except Exception, e:  # Wrong syntax

# Python 3 (correct)
print("Hello")
except Exception as e:
3Check indentation

Python is sensitive to indentation. Use spaces consistently (no tabs):

python
if x > 5:
    print("Greater than 5")  # Indented with spaces
  print("Wrong")  # Wrong indentation - mixes levels
4Match parentheses and quotes

Ensure all parentheses, brackets, and quotes are balanced:

python
# Wrong
mylist = [1, 2, 3
result = func(param1, param2

# Correct
mylist = [1, 2, 3]
result = func(param1, param2)
5Use a linter

Tools catch syntax errors before runtime:

bash
pip install pylint flake8
pylint your_script.py
flake8 your_script.py

Advanced notes

Most IDEs highlight syntax errors immediately. Use IDE's syntax checker or a pre-commit hook to catch these before running code.

Frequently asked questions

What does "SyntaxError: non-default argument follows default argument" mean?
The "SyntaxError" error means Python's parser found code that doesn't follow Python's syntax rules. Unlike runtime errors, this happens before code even runs. Common causes: 1.
How do I fix "SyntaxError: non-default argument follows default argument"?
SyntaxError means your Python code has invalid syntax that violates Python's grammar rules. The error message usually points near the problem. Common issues are missing colons, incorrect indentation, or mismatched parentheses.
What causes "SyntaxError: non-default argument follows default argument"?
Missing colon after if/for/while/def statements Indentation error Mismatched parentheses, brackets, or quotes
Is the "SyntaxError: non-default argument follows default argument" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading