SyntaxError: unexpected EOF while parsing (Fix)
SyntaxError: unexpected EOF while parsing means Python reached the end of your file before the code was complete.
This usually happens when something is missing, such as:
- a closing quote
- a closing parenthesis
- a closing bracket
- a closing brace
- the rest of an unfinished statement
This page will help you find the missing part, fix the syntax, and understand why Python shows this error.
Quick fix
A complete statement looks like this:
name = input("Enter your name: ")
print(name)
This error usually means Python expected something more before the file ended.
Check for:
- a missing closing quote
- a missing
) - a missing
] - a missing
} - an unfinished function call or expression
What this error means
Python reads your code from top to bottom.
When you get SyntaxError: unexpected EOF while parsing, Python is saying:
- it got to the end of the file
- it was still expecting more code
- something earlier was left incomplete
EOF means end of file.
In many cases, the line shown in the error is not the real problem. The mistake is often on the same line or a line above it.
If you want a broader overview of how syntax problems work, see Python syntax basics explained and Python errors and exceptions explained.
Why this happens
This error is commonly caused by one of these problems:
- A parenthesis was opened but not closed.
- A string started with a quote but never ended.
- A list, tuple, dictionary, or set was not closed.
- A function call or expression was left unfinished.
- A multi-line statement was started but not completed.
Example: missing closing parenthesis
Here is a common example:
print("Hello"
Python expects a closing ) but reaches the end of the file first.
Fix
print("Hello")
Why this works
The print() function call starts with ( and must end with ).
Example: missing quote
If a string starts but never ends, Python keeps reading until the file ends.
Bad code
message = "Hello
print(message)
Fix
message = "Hello"
print(message)
Why this works
Strings must have both an opening and a closing quote.
If your problem is specifically caused by an unclosed string, see SyntaxError: EOL while scanning string literal.
Example: unfinished list or dictionary
This can also happen with collections.
Bad code
numbers = [1, 2, 3
print(numbers)
Python expects the closing ].
Another example:
person = {
"name": "Ana",
"age": 25
print(person)
Python expects the closing }.
Fix
numbers = [1, 2, 3]
print(numbers)
person = {
"name": "Ana",
"age": 25
}
print(person)
Why this works
Lists, dictionaries, tuples, and sets must be fully closed before Python can continue.
Check collection literals carefully, especially when they span multiple lines.
How to fix it step by step
Use this process when you see the error:
- Read the line shown in the error message.
- Check the line above it too.
- Match every opening symbol with a closing symbol:
(with)[with]{with}
- Check that all strings have both opening and closing quotes.
- Look for unfinished function calls or expressions.
- If needed, delete the broken line and type it again carefully.
For example, this unfinished expression causes the same problem:
total = 10 +
Python expects something after the +.
Fix
total = 10 + 5
print(total)
Fast debugging checklist
When you need to fix the error quickly, check these first:
- Count
(,[, and{characters and make sure they are closed. - Check for single or double quotes that were not closed.
- Look for a comma or operator at the end of a line with no next value.
- Check code copied from the web for missing last characters.
- Use an editor that highlights matching brackets.
You can also run your file from the command line:
python your_script.py
Or check the file for syntax problems with:
python -m py_compile your_script.py
Common causes
These are the most common reasons for this error:
- Missing closing parenthesis
) - Missing closing bracket
] - Missing closing brace
} - Unclosed string quote
- Unfinished function call
- Incomplete expression at the end of the file
A more general syntax page may also help if the message is less clear: SyntaxError: invalid syntax.
Related errors to compare
Some syntax errors look similar but mean different things:
- SyntaxError: EOL while scanning string literal is more specific for unclosed strings.
- SyntaxError: missing colon happens when Python expects
:afterif,for,while,def, orclass. - IndentationError: expected an indented block happens when the syntax is otherwise valid, but the block indentation is wrong.
FAQ
What does EOF mean in Python?
EOF means end of file. Python got to the end of your code while still expecting more syntax.
Is the error always on the last line?
No. The real problem is often earlier, such as an unclosed quote or bracket on a previous line.
Can this happen with copy-pasted code?
Yes. Code can be missing a closing character or may have been cut off when copied.
How do I find the missing symbol quickly?
Check matching pairs: (), [], {}, and quotes. Most editors also highlight matching brackets.