All Python errors
SyntaxError: unterminated string literal
This message means a string was opened with a quote and the line ended before the matching quote. To fix it, close the text on the same line with the same kind of quote, or use triple quotes for several lines.
Code with the error
greeting = "Good morning
print(greeting)
Error message (Python 3.12, last line)
Corrected code
greeting = "Good morning"
print(greeting)
Output
Good morning
Common causes
- The closing quote is forgotten.
- The string starts with one kind of quote and ends with another.
- An apostrophe inside single quotes ends the text too early.
- A long text is broken into two lines without triple quotes.
Practise in the course
Lesson: StringsFrequently asked questions
How do I write an apostrophe inside a string?
Wrap the text in double quotes, for example "It's fine".
How do I write text on several lines?
Use triple quotes around it, or put \n where a new line should start.