Editor settings

General settings

Save settings

Learn to program with Python

Mismatched quotation mark #

Python supports both single ' and double " quotation marks for representing strings. It is important to use matching quotation marks to define string literals correctly.

Mismatched quotation mark errors occur when the opening and closing quotation marks in a string literal do not match. Python interprets the mismatched quotation marks as a syntax error and raises a SyntaxError.

For example, this will cause an error, because we use a single quotation mark at the beginning, but use a double quotation mark at the end:

sentence = 'Hello World!"

If you need to include the same type of quotation mark within a string, use an escape character \ before the quotation mark to indicate that it is part of the string and not the closing delimiter.

For example:

sentence = 'I\'m doing great, thanks!'

Exercise #

  • Fix the code so that it uses the correct quotation mark to define the string.
  • Make sure the quotation mark(s) are escaped correctly.

Tests #

  • Variable message should be the sentence He said, "Don't forget to bring your umbrella!"
Output will be displayed here