The informational document PEP 257 -- Docstring Conventions recommends to use """triple double-quotes""" for consistency, and all their examples show the same:

For consistency, always use """triple double quotes""" around docstrings. Use r"""raw triple double quotes""" if you use any backslashes in your docstrings.

Whether to use single quotes or double quotes is only a stylistic issue in practice. There will be no difference in formatting when generating and publishing docs from these strings.

Note that code formatters such as black will enforce triple double-quotes for docstrings.

Answer from wim on Stack Overflow
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ pythonic way to use single quotation mark vs, double quotation mark?
r/learnpython on Reddit: Pythonic way to use single quotation mark vs, double quotation mark?
February 10, 2019 -

Is there a "rule of thumb" to decide whether to use single quotation mark or double quotation mark? For example, I've seen some people use single quotation mark for small symbol-like strings and double single quotation mark for interpolation or that are natural language messages.

Or is it simply a personal preference and being consistent with whatever style you have for yourself? Obviously, the offical docs state that we can use whichever matching quotes, but I'd like to know if there is a pythonic way to use them.

Discussions

Formatter: Docstrings with `quote-style = "single"` configuration
Worth checking what the single-quote ... to use double quotes for docstrings even when enforcing single quotes ยท For me it would be important that docstrings always use """ regardless of quote-style. I am not quite sure if this is to be understood as a feature request or rather as ... More on github.com
๐ŸŒ github.com
30
September 23, 2023
coding style - Single quotes vs. double quotes in Python - Stack Overflow
This answer is contrary to python ... double quotes""" around docstrings. python.org/dev/peps/pep-0257 2013-06-10T23:36:14.2Z+00:00 ... Save this answer. ... Show activity on this post. ... I'll stick with that even if it means a lot of escaping. I get the most value out of single quoted identifiers ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Triple double-quotes used as a docstring or multi-line string?
A triple quote is a way to make strings. They lend themselves to multiline stings because you don't have to escape the newlines. The the only connection with docstrings is tradition. A docstring is just a sting that immediately follows a definition. class Test: "docstring" "not a docstring" def method(self): "method docstring" a = 'just a normal string' def another_method(self): """ another method docsting """ A lone string that does not immediately follow a definition is evaluated and then thrown out, basically ignored by python, so it's often used as a form of commenting. More on reddit.com
๐ŸŒ r/learnpython
3
5
October 23, 2017
Which is more popular to use to quote strings, single quote('string') or double quote("string")?
Other languages tend to use double quotes for strings and single quotes for single characters. Python doesn't require it, but if you get into that habit, it won't be something you have to change when learning a new language More on reddit.com
๐ŸŒ r/learnpython
16
2
August 27, 2022
๐ŸŒ
Python
peps.python.org โ€บ pep-0257
PEP 257 โ€“ Docstring Conventions | peps.python.org
String literals occurring immediately ... description of attribute and additional docstrings. For consistency, always use """triple double quotes""" around docstrings....
๐ŸŒ
CKAN
docs.ckan.org โ€บ en โ€บ ckan-2.1.5 โ€บ python-coding-standards.html
Python Coding Standards โ€” CKAN Documentation 2.1.5 documentation
Single-quotes are easier to read and to type, but if a string contains single-quote characters then double-quotes are better than escaping the single-quote characters or wrapping the string in double single-quotes. We also use triple single-quotes for docstrings, see Docstrings.
๐ŸŒ
Towards Data Science
towardsdatascience.com โ€บ home โ€บ latest โ€บ python single vs. double quotesโ€Š-โ€Šwhich should you use and why?
Python Single vs. Double Quotes - Which Should You Use And Why? | Towards Data Science
November 27, 2024 - You're free to use both ''' and """ to surround a docstring, but the convention is to use the latter. Long story short - the differences between single and double quoted strings in Python are minimal.
๐ŸŒ
Codecademy
codecademy.com โ€บ forum_questions โ€บ 508186b293ac6f020000172a
Shouldn't this lesson also be "solved" using three single quotes? | Codecademy
The style guide at python.org does call out triple double-quotes as what you should use โ€œfor consistencyโ€ in a docstring ( http://www.python.org/dev/peps/pep-0257/#what-is-a-docstring ), however either will work.
๐ŸŒ
GitHub
github.com โ€บ astral-sh โ€บ ruff โ€บ issues โ€บ 7615
Formatter: Docstrings with `quote-style = "single"` configuration ยท Issue #7615 ยท astral-sh/ruff
September 23, 2023 - Following #1904 (comment) I tried the new configuration [tool.ruff.format] # Use single quotes rather than double quotes. quote-style = "single" But now docstrings are also formatted with single quotes: def func(): '''Docstring.''' strin...
Author: astral-sh
Find elsewhere
๐ŸŒ
Betterdatascience
betterdatascience.com โ€บ python-single-vs-double-quotes
Python Single vs. Double Quotes - Which Should You Use And Why? | Better Data Science
January 17, 2022 - Youโ€™re free to use both ''' and """ to surround a docstring, but the convention is to use the latter. Long story short - the differences between single and double quoted strings in Python are minimal.
๐ŸŒ
pythontutorials
pythontutorials.net โ€บ blog โ€บ what-s-the-difference-on-docstrings-with-triple-single-quotes-and-triple-double-quotes
What's the Difference Between Triple Single and Double Quotes in Python Docstrings? โ€” pythontutorials.net
Docstrings can be single-line (for short descriptions) or multi-line (for detailed explanations, arguments, return values, etc.). Both triple single and double quotes support multi-line docstrings, but their usage depends on context.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-docstrings
Python Docstrings - GeeksforGeeks
August 2, 2024 - Unlike conventional source code comments, the docstring should describe what the function does, not how. Declaring Docstrings: The docstrings are declared using '''triple single quotes''' or """ triple double quotes """ just below the class, ...
๐ŸŒ
Codingem
codingem.com โ€บ home โ€บ python single quote vs double quote
Python Single Quote vs Double Quote - codingem.com
December 12, 2022 - Read more about docstrings in Python. In Python, you can create a string with double quotation marks or single quotation marks.
๐ŸŒ
Devgex
devgex.com โ€บ en โ€บ article โ€บ 00003301
Single Quotes vs. Double Quotes in Python: Usage Norms and Best Practices - DevGex
November 1, 2025 - # Single quotes for short identifiers key = 'user_id' # Double quotes for natural language strings with interpolation greeting = "Hello, %s!" % username # Triple double quotes for multiline strings and docstrings description = """This is a ...
๐ŸŒ
Execute Program
executeprogram.com โ€บ courses โ€บ python-for-programmers โ€บ lessons โ€บ docstrings
Docstrings Lesson - Python for Programmers
But the .__doc__ attribute also works with single-quoted strings. ... Functions that don't include a docstring still have a .__doc__ attribute, but its value is always None. ... Strings only become docstrings when they're the first statement in a function. A string anywhere else in the function has no effect. ... Docstrings aren't just for our code. Python uses them extensively throughout the language and standard library. When we're at a REPL (a Python shell or console), we can call help on any value.
๐ŸŒ
sqlpey
sqlpey.com โ€บ python โ€บ python-string-quotes-single-vs-double
Python String Quotes: Single vs Double for Consistency and Context
November 4, 2025 - ANS: No, for standard string literals, there is no measurable performance difference in Python between using single quotes (โ€™) or double quotes ("). ANS: PEP 257 strongly recommends using triple double quotes ("""...""") for docstrings, as this convention is far more prevalent in the Python ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ triple double-quotes used as a docstring or multi-line string?
r/learnpython on Reddit: Triple double-quotes used as a docstring or multi-line string?
October 23, 2017 -

"A docstring is a string literal that occurs as the first statement in a module, function, class, or method definition. Such a docstring becomes the _doc_ special attribute of that object."

I thought triple double quotes were only used as docstrings but I came across a SQL command using triple quote for multi line purposes and avoid escaping, I think

    rows = db.execute("""SELECT * FROM places
        WHERE :sw_lat <= latitude AND latitude <= :ne_lat AND (:sw_lng <= longitude AND longitude <= :ne_lng)
        GROUP BY country_code, place_name, admin_code1
        ORDER BY RANDOM()
        LIMIT 10""",
        sw_lat=sw_lat, ne_lat=ne_lat, sw_lng=sw_lng, ne_lng=ne_lng)

In this case, triple quotes are just treated as a string literal but not a doc special attribute. How's one treated like a docstring and not the other? Then is this considered as a simple string literal not docstring?:

def foo():
    somecode """docstring"""
๐ŸŒ
CKAN
docs.ckan.org โ€บ en โ€บ ckan-2.2.3 โ€บ python-coding-standards.html
Python coding standards โ€” CKAN 2.2.3 documentation
Single-quotes are easier to read and to type, but if a string contains single-quote characters then double-quotes are better than escaping the single-quote characters or wrapping the string in double single-quotes. We also use triple single-quotes for docstrings, see Docstrings.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ what is your preferred style of quoting strings?
r/learnpython on Reddit: What is your preferred style of quoting strings?
April 14, 2025 -

PEP-8 is quite flexible about how to quote strings:

In Python, single-quoted strings and double-quoted strings are the same. This PEP does not make a recommendation for this. Pick a rule and stick to it. When a string contains single or double quote characters, however, use the other one to avoid backslashes in the string. It improves readability.

For triple-quoted strings, always use double quote characters to be consistent with the docstring convention in PEP 257.

Styles observed in the wild:

Excluding docstrings, (as PEP-257 clearly states "always use """triple double quotes""""), which do you prefer?

  • Single quotes always.

  • Double quotes always.

  • Single quotes unless the quoted string includes apostrophes.

  • Double quotes unless the quoted string includes double quotes.

  • Double quotes for user-facing string, and single quotes for other (code) str values.

  • Double quotes for multi-character strings, single quote for single character.

  • Other (please specify).