Jan 18, 2021
Tags: python
SyntaxError: unterminated string literal (detected at line 9)
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:
- Added a newline after the string definition (
my_string = 'Hello World'
) to separate it from the print statement. - Closed the f-string with a closing curly brace (
}
) after the{5}
expression.
With these corrections, the code should run without a syntax error.
Comments
-
Danielle Carline
Posted on
Close the string in the print statement.
my_string = 'Hello World'print(f"{my_string}, {5}")