How do you style docstrings in python?
Question:
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
Answers:
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.
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
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.