The simplest option is to surround the string with double quotes:
message = "I can't wait."
print(message)You can also use single quotes and escape the apostrophe:
message = 'I can\'t wait.'
print(message)Both examples print I can't wait. The backslash in the second example belongs to the source syntax; it is not printed.
When text contains both kinds of quote
message = "She said, \"I can't wait.\""
print(message)Escape the delimiter used around the string. Triple-quoted strings can be convenient for multiple lines, but they still have delimiters and escape rules.
Common mistakes
- Do not use a word processor’s curly quotation marks as Python string delimiters.
- An apostrophe can appear as text inside a properly quoted string.
- Seeing quotes in the interactive representation of a string is different from printing its contents with
print().
Try strings as keys in a Python dictionary, or learn how Unicode text and identifiers differ.
Sources and verification
All three string examples are executed in the local Python verification run.
