All Python errors
SyntaxError in Python: '(' was never closed
This message means a bracket was opened and Python reached the end of the code without finding its pair. To fix it, start at the line in the message and add the closing ), ] or } where the expression ends.
Code with the error
width = 6
height = 4
print((width + height) * 2
print("done")
Error message (Python 3.12, last line)
Corrected code
width = 6
height = 4
print((width + height) * 2)
print("done")
Output
20
done
Common causes
- One closing bracket is missing after nested calls such as print(len(items).
- A list or a dictionary written on several lines has no final ] or }.
- A bracket was deleted while editing the line.
- The closing bracket is inside quotes, so Python reads it as text.
Practise in the course
Lesson: Math OperationsFrequently asked questions
Why does the message name an earlier line than the one I was editing?
It points at the line where the unclosed bracket was opened. Look from there downwards.
Does the same message exist for square and curly brackets?
Yes: '[' was never closed and '{' was never closed are fixed the same way.