Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Python ordinary strings can use either single quotes or double quotes, with the same parsing result. Choose the delimiter that makes the text easiest to read; if the text contains that same quote character, switch delimiters or escape it with a backslash.

Can Python strings use either single or double quotes?

Yes. For ordinary string literals, Python treats single-quoted and double-quoted forms equivalently. As the Python 3.14.8 tutorial puts it, “They can be enclosed in single quotes ('...') or double quotes ("...") with the same result.” Python tutorial: Text.

The opening delimiter must match the closing delimiter. The other kind of quote can appear inside the string without an escape:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
message = "Don't do that!"
greeting = 'Say "Hello".'

These assignments create ordinary string values; neither quote style has a special meaning that changes the value. Pick the form that avoids unnecessary escaping and keeps the text clear.

How do I put a quote or apostrophe inside a string?

If the text contains the delimiter you chose, put a backslash before that character. Alternatively, change the outer delimiter if that makes the line clearer.

contraction = 'doesn't'
spoken = "Say "Hello"."
also_clear = "doesn't"

In an ordinary string, a backslash introduces an escape sequence. Common examples include ' and " for quote characters, \ for a literal backslash, n for a linefeed, and t for a tab. See the Python language reference on string and bytes literals.

When should I use triple quotes?

Triple-quoted literals use three single quotes or three double quotes. They are useful for text that spans source-code lines: unescaped newlines are retained in the resulting string. Either kind of quote can appear within the string, as long as it does not form three matching, unescaped quote marks that close the literal.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
poem = '''First line
Second line'''
quote = '''She said, "It's ready."'''

Choose the triple-quote style that avoids escaping the content. A triple-quoted string ends at the next matching, unescaped sequence of three delimiters; it is not simply closed by any quote mark inside it. The language reference describes the literal rules.

What do raw strings change about quotes?

A raw string adds an r prefix immediately before its opening quote. It changes how backslashes are handled, which can be useful for regular-expression patterns or Windows-style paths; it does not remove the requirement for a matching closing quote.

pattern = r"d+"
path = r"C:UsersAdaDocuments"

Raw strings cannot end in an odd number of backslashes, because the final backslash would escape the closing quote. For example, r"C:folder" is invalid. Use a different spelling, such as "C:\folder\", or build the final separator separately. Prefix behavior and literal syntax are documented in the Python language reference.

Why does Python show quotes when I inspect a string?

The interactive shell displays a string’s representation, which may include surrounding quote marks and visible escapes. print() displays the string’s contents instead, interpreting newlines and other special characters. Those are two views of the same value, not evidence that the string changed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
>>> text = "FirstnSecond"
>>> text
'FirstnSecond'
>>> print(text)
First
Second

The representation uses quote marks to show where the value begins and ends, and n to make the embedded linefeed visible. Printing writes that linefeed as a new line.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Which quote style should I choose?

Because single- and double-quoted ordinary strings parse the same way, choose based on readability and the characters in the text. These examples show the practical choices:

String content Clear spelling Why
An apostrophe "Don't do that!" The apostrophe does not need escaping.
Double quotation marks 'Say "Hello".' The inner double quotes do not need escaping.
Both quote types Choose the outer delimiter that makes the line easiest to read, escaping matching inner quotes as needed. Only an inner quote matching the outer delimiter needs escaping.
Text across source lines Use triple single or triple double quotes, whichever avoids escaping the content. Unescaped newlines are retained.

For a team project, follow the project’s existing style consistently. The language itself does not require one ordinary quote style over the other.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.