Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do you style docstrings in python?

I want to style docstrings but I wasn’t able to find a clear document detailing how to go about it

"""
line 1 - I want this in bold

line 2 - I want this in italics

line 3 - I want the text color different

/n

line 4 - I want this line to have 2 blank lines ontop of it
"""

No matter the amount of blank lines I put inside the docstring they only produce a single newline for every line, the \n character does nothing. Could anyone point me to how I could do things line change colors, bold, and indentation and spaces? Thank you!

EDIT:
For reference I am using pycharm, if there is a difference between how docstrings work between vscode or other IDEs

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

To include special formatting in a docstring, you can use bold, italics, or monospace text. You can also use inline code blocks by enclosing the code in backticks (“`). Here is an example:

def my_function():
    """
    This is a docstring.
    
    **Bold**, *italics*, and `monospace` text are supported.
    
    This is an inline code block: `print('Hello, world!')`
    """
    pass

You cannot change the text color or add extra blank lines inside a docstring. Docstrings are plain text, and do not support any kind of special formatting or layout. The purpose of docstrings is to document the code, not to add visual formatting.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading