Code with the error

greeting = "Good morning
print(greeting)

Error message (Python 3.12, last line)

SyntaxError: unterminated string literal (detected at line 1)

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: Strings

Frequently 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.