Jan 18, 2021 1 mins

SyntaxError: unterminated string literal (detected at line 9)

Learn Python Learn Python

SyntaxError: unterminated string literal (detected at line 9) when printing below string.

my_string = 'Hello World'print(f"{my_string}, {5})

The code has a syntax error due to an unterminated string literal and a mismatched closing parenthesis. The corrected code should look like this:

my_string = 'Hello World'
print(f"{my_string}, {5}")

Changes made:

  1. Added a newline after the string definition (my_string = 'Hello World') to separate it from the print statement.
  2. Closed the f-string with a closing curly brace (}) after the {5} expression.

With these corrections, the code should run without a syntax error.


  • Avatar

    Danielle Carline

    Posted on

    Close the string in the print statement.

    my_string = 'Hello World'print(f"{my_string}, {5}")

Write a comment

You can use the Markdown syntax to format your comment.

  • Tags:
  • python
  • Share: