TryBugHunt

SyntaxError: '(' was never closed

SyntaxError: '(' was never closed in Python means you opened a bracket — (, [ or { — and never closed it. Python reached the end of the file still waiting for the closing one.

Python

How do I fix SyntaxError: '(' was never closed?

SyntaxError: '(' was never closed means you opened a bracket and Python reached the end of the file without finding its partner. The common case is nested calls like int(input("Age: ")) with one ) missing. Go to the bracket the message points at and add the closing ), ] or } in the right place.

  1. 1. Go to the open bracketPython 3.10 and newer point at the bracket left open, which may be several lines above where things look wrong.
  2. 2. Count brackets per lineCount each ( and ), [ and ], { and }. Nested calls need one ) for every (.
  3. 3. Close multi-line listsA list or dictionary over several lines needs its closing ] or } before the next statement.

What does SyntaxError: '(' was never closed mean?

Every opening bracket needs a matching closing bracket. Python 3.10 and newer point at the bracket that was left open. Older versions often blame the next line with a plain "invalid syntax", which sends people looking in the wrong place. The opposite mistake, an extra closing bracket, gives "SyntaxError: unmatched ')'", and closing with the wrong kind, like { ... ), gives "closing parenthesis ')' does not match opening parenthesis '{'".

Why does SyntaxError: '(' was never closed happen?

1. A missing ) at the end of a call

Nested calls need one ) for each (. Here int( and input( both open, but only one closes.

Breaks

age = int(input("Age: ")

Works

age = int(input("Age: "))

2. A list or dictionary that is not closed

Lists over several lines are fine, but the closing bracket is easy to forget.

Breaks

colours = [
    "red",
    "green",

print(colours)

Works

colours = [
    "red",
    "green",
]
print(colours)

3. A bracket left open on an earlier line

Python keeps reading the next lines as part of the same expression, so the error can appear far below the real mistake.

Breaks

user = {
    "name": "Ada",
    "age": 36

print(user)

Works

user = {
    "name": "Ada",
    "age": 36
}
print(user)

How to find it in your own code

Checklist: 1) Go to the bracket the message points at. 2) Count opening and closing brackets on that line; they must be equal. 3) Check each closing bracket is the same kind as its opener: ( with ), [ with ], { with }. 4) Most editors highlight the matching bracket when you put the cursor next to one; use that to find which one has no partner.

Still not sure why yours breaks?

Paste it into the visualizer and watch it run line by line, with every variable at every step. Free, and it runs in your browser.

Related error guides