print produces plain text, not Microsoft Word documents. If you add HTML formatting tags (<html>, <body>, <strong>, <br />, etc.) where necessary, then give the resulting text file the .doc extension, it will open with Word, which - assuming you have a reasonably recent version that understands HTML - will parse the HTML and display the result you're looking for.

Sample:

a= '<html><head></head><body>Hi %s, </br> The meeting is scheduled for <strong>%s %sth</strong> <br /> if you have an  questions please contact %s</body></html>' % (cfname, meetingmonth, meetingday, cleadfname)
Answer from TigerhawkT3 on Stack Overflow
🌐
GitHub
github.com › glyph › python-docstring-mode › blob › master › python-docstring.el
python-docstring-mode/python-docstring.el at master · glyph/python-docstring-mode
(,python-docstring-sphinx-markup-code 1 '(bold italic) t) · ;; L/U - 1 · (,python-docstring-epytext-markup-link 0 font-lock-constant-face t) ;; Inline Markup - 1 · (,python-docstring-epytext-markup-link 1 font-lock-function-name-face t) ;; Link - 2 ·
Author: glyph
🌐
JetBrains
youtrack.jetbrains.com › issue › PY-40010
Python docstring rendering: reStructuredText markup inside ...
October 21, 2022 - Our website uses some cookies and records your IP address for the purposes of accessibility, security, and managing your access to the telecommunication network. You can disable data collection and cookies by changing your browser settings, but it may affect how this website functions.
🌐
Lsst
developer.lsst.io › python › numpydoc.html
Documenting Python APIs with docstrings — LSST DM Developer Guide main documentation
Conventional reStructuredText subsections are not allowed in docstrings, given the previous guideline. However, you may structure long sections with bold text that simulates subsection headers. This technique is useful for the Notes and Examples Numpydoc sections.
🌐
KidsCodecs
kidscodecs.com › docstrings
docstrings – 30 STEM Links a Week
In this example, note the triple double quotes around the docstring. This is the same syntax as docstrings in Python. However, note the **formatting** bit of the docstring. The double stars are Markdown syntax; when processed, the double stars will convert text to bold.
🌐
Umd
admit.astro.umd.edu › style.html
Documentation Style Guide — ADMIT 1.0.8 documentation
In class docstrings, for text referencing internal class methods from outside said method, it is good style to use bold type to highlight the method name; e.g., “The use of foo() over bar() is preferred whenever possible...” With sufficient care, it is also possible to construct live hyperlink ...
🌐
SourceForge
epydoc.sourceforge.net › manual-epytext.html
The Epytext Markup Language - Epydoc
Tabs (\011) are expanded to spaces, using the same algorithm used by the Python parser. Carridge-return/newline pairs (\015\012) are converted to newlines. Characters in a docstring that are not involved in markup are called content characters. Content characters are always displayed as-is. In particular, HTML codes are not passed through. For example, consider the following example: The docstring is rendered as <B>test</B>, and not as the word "test" in bold face.
🌐
Readthedocs
clize.readthedocs.io › en › stable › docstring-reference.html
Customizing the help using the docstring — clize 5.0.2 documentation
Clize draws the text of the --help output from your function’s docstring. In addition, it will draw documentation for parameters added by decorators from the function that defined it. The recommended way of formatting parameters is just like you would when using Sphinx’s autodoc. The format is explained with examples below. For those who are already familiar with it, there are a few notable differences: Formatting (bold, italics, etc), tables and bullet points are ignored.
🌐
Noirlab
datalab.noirlab.edu › docs › manual › DevGuide › DocumentingPythonAPIswithDocstrings › DocumentingPythonAPIswithDocstrings.html
3.2. Documenting Python APIs with Docstrings — Data Lab documentation
Conventional reStructuredText subsections are not allowed in docstrings, given the previous guideline. However, you may structure long sections with bold text that simulates subsection headers. This technique is useful for the Notes and Examples Numpydoc sections.
Find elsewhere
🌐
Python-sprints
python-sprints.github.io › pandas › guide › pandas_docstring.html
pandas docstring guide — Python documentation
In rare occasions reST styles like bold text or itallics will be used in docstrings, but is it common to have inline code, which is presented between backticks. It is considered inline code: ... Python code, a module, function, built-in, type, literal…
🌐
Pandas
pandas.pydata.org › docs › development › contributing_docstring.html
pandas docstring guide — pandas 3.0.5 documentation
The examples should be as concise as possible. In cases where the complexity of the function requires long examples, is recommended to use blocks with headers in bold.
Top answer
1 of 6
1389

Formats

Python docstrings can be written following several formats as the other posts showed. However the default Sphinx docstring format was not mentioned and is based on reStructuredText (reST). You can get some information about the main formats in this blog post.

Note that the reST is recommended by the PEP 287

There follows the main used formats for docstrings.

- Epytext

Historically a javadoc like style was prevalent, so it was taken as a base for Epydoc (with the called Epytext format) to generate documentation.

Example:

"""
This is a javadoc style.

@param param1: this is a first param
@param param2: this is a second param
@return: this is a description of what is returned
@raise keyError: raises an exception
"""

- reST

Nowadays, the probably more prevalent format is the reStructuredText (reST) format that is used by Sphinx to generate documentation. Note: it is used by default in JetBrains PyCharm (type triple quotes after defining a method and hit enter). It is also used by default as output format in Pyment.

Example:

"""
This is a reST style.

:param param1: this is a first param
:param param2: this is a second param
:returns: this is a description of what is returned
:raises keyError: raises an exception
"""

- Google

Google has their own format that is often used. It also can be interpreted by Sphinx (ie. using Napoleon plugin).

Example:

"""
This is an example of Google style.

Args:
    param1: This is the first param.
    param2: This is a second param.

Returns:
    This is a description of what is returned.

Raises:
    KeyError: Raises an exception.
"""

Even more examples

- Numpydoc

Note that Numpy recommend to follow their own numpydoc based on Google format and usable by Sphinx.

"""
My numpydoc description of a kind
of very exhautive numpydoc format docstring.

Parameters
----------
first : array_like
    the 1st param name `first`
second :
    the 2nd param
third : {'value', 'other'}, optional
    the 3rd param, by default 'value'

Returns
-------
string
    a value in a string

Raises
------
KeyError
    when a key error
OtherError
    when an other error
"""

Converting/Generating

It is possible to use a tool like Pyment to automatically generate docstrings to a Python project not yet documented, or to convert existing docstrings (can be mixing several formats) from a format to an other one.

Note: The examples are taken from the Pyment documentation

2 of 6
354

The Google style guide contains an excellent Python style guide. It includes conventions for readable docstring syntax that offers better guidance than PEP-257. For example:

def square_root(n):
    """Calculate the square root of a number.

    Args:
        n: the number to get the square root of.
    Returns:
        the square root of n.
    Raises:
        TypeError: if n is not a number.
        ValueError: if n is negative.

    """
    pass

I like to extend this to also include type information in the arguments, as described in this Sphinx documentation tutorial. For example:

def add_value(self, value):
    """Add a new value.

       Args:
           value (str): the value to add.
    """
    pass
🌐
GitHub
github.com › lsst-dm › dm_dev_guide › blob › main › python › numpydoc.rst
dm_dev_guide/python/numpydoc.rst at main · lsst-dm/dm_dev_guide
Conventional reStructuredText subsections are not allowed in docstrings, given the :ref:`previous guideline <py-docstring-section-levels>`. However, you may structure long sections with bold text that simulates subsection headers. This technique is useful for the :ref:`Notes <py-docstring-notes>` and :ref:`Examples <py-docstring-examples>` Numpydoc sections.
Author: lsst-dm
🌐
GitHub
github.com › microsoft › pylance-release › issues › 2264
Help window tooltip **bold** rendering · Issue #2264 · microsoft/pylance-release
January 19, 2022 - Hello. First thanks for great job about help tooltip. Links, bullets , headings works just great. Is it possible to add rendering of bold text with asterisks syntax (both in rst as well as in markdown). Printscreen how its rendered now.....
Author: microsoft
🌐
GitHub
github.com › emacsmirror › python-docstring › blob › master › python-docstring.el
python-docstring/python-docstring.el at master · emacsmirror/python-docstring
(,python-docstring-sphinx-markup-code 1 '(bold italic) t) · ;; L/U - 1 · (,python-docstring-epytext-markup-link 0 font-lock-constant-face t) ;; Inline Markup - 1 · (,python-docstring-epytext-markup-link 1 font-lock-function-name-face t) ;; Link - 2 ·
Author: emacsmirror
🌐
GitHub
github.com › microsoft › vscode-python › issues › 6676
Documentation for how to format docstrings for correct tooltips using Jedi · Issue #6676 · microsoft/vscode-python
July 23, 2019 - From my understanding of reading things like DonJayamanne#38 and #107, it's possible for python to display function parameters like javascript: However, I've tried every docstring format under the sun I can find (and tried both Jedi and ...
Author: microsoft