Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

Python Quotes Made Simple: Choose, Escape, and Print Strings Correctly

Python single and double quotes create equivalent ordinary strings. Choose the clearer delimiter, escape matching inner quotes, and use triple quotes for multiline text.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Python treats ordinary single-quoted and double-quoted strings the same. Choose the delimiter that makes the text easiest to read: use double quotes around an apostrophe, single quotes around a double quote, or escape an inner quote that matches the delimiter.

Can Python strings use either single or double quotes?

Yes. An ordinary string literal can begin and end with either single quotes or double quotes, and Python parses both choices the same way. The opening delimiter must match the closing delimiter. As the Python 3.14.8 tutorial puts it, “They can be enclosed in single quotes ('...') or double quotes ("...") with the same result.” Python’s official tutorial covers this in its Text section.

As an Amazon Associate I earn from qualifying purchases.

Pick the style that makes the contents clearest. If a project or team has a consistent style convention, follow it; the delimiter choice itself does not change the string’s meaning.

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

How do you put quotes or apostrophes inside a string?

If the quote inside the text differs from the string’s outer delimiter, write it directly. If it matches, escape it with a backslash or choose the other delimiter.

Text you want Python literal Why it works
Don’t do that! "Don't do that!" The apostrophe is inside a double-quoted string.
Say “Hello”. 'Say "Hello".' The double quotes are inside a single-quoted string.
doesn’t 'doesn't' The apostrophe matches the outer delimiter, so the backslash escapes it.
Say “Hello”. "Say "Hello"." Each matching inner double quote is escaped.

A backslash in an ordinary string begins an escape sequence. For example, n represents a linefeed, t a tab, and \ one literal backslash. ' and " represent quote characters. See the official lexical analysis reference for string-literal rules.

When should you use triple quotes?

Triple single quotes ('''...''') and triple double quotes ("""...""") let a string span source-code lines. Newlines within the literal are retained as part of the string. Choose the triple delimiter that avoids awkward escaping of quote sequences in the text.

message = """First line
Second line"""
print(message)

Three matching, unescaped quote marks end the literal. Quotes of either kind can appear inside a triple-quoted string unless they form that closing sequence. The string-literal reference describes the termination rules.

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

Do raw strings change quote rules?

A raw string uses an r prefix immediately before its opening quote, as in r"C:newfolder". It is useful when backslashes should remain literal, such as in many patterns or Windows-style paths. Raw strings still need a matching closing delimiter; the prefix does not let an unescaped matching quote pass through.

A raw string also cannot end in an odd number of backslashes, because the final backslash would escape the closing quote. For example, r"folder" is invalid. For the current details on raw strings and other prefixes, consult the Python language reference.

Why does Python show quotes when you inspect a string?

Evaluating a string variable in the interactive shell displays a representation of the value. That representation may include quote marks and visible escapes so the value can be distinguished and understood. Calling print() displays the string’s contents instead.

text = "Don'tnstop"
text
print(text)

The interactive representation shows the value with escaped newline notation; print(text) renders the newline as a line break. These are two views of the same string, not evidence that Python changed it. The tutorial explains this distinction in its Text section.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What about formatted strings and other prefixes?

String prefixes go directly before the opening quote, as in f"Hello, {name}" for a formatted string. Prefixes can affect how a literal is interpreted, but they do not remove the requirement for a valid opening and closing delimiter. Which prefixes can be combined and what they do are specified in the current language reference.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.