Internal documentation
Docstrings and type hints comments
|
Python utilises docstrings and type hints to document code. Docstrings are multi-line strings that provide information about modules, classes, functions and methods. Type hints, on the other hand, allow for specifying the expected types of function parameters and return values. Docstrings and type hints are used in Python:
Use
Only comment parts of your code that are important, interesting or not obvious. Use correct grammar and spelling in comments. You can read more about Python docstring conventions at PEP257. Type hintsPython allows you to provide type hints for function parameters and return values, although they are not enforced at runtime. This helps document the expected types of values. Example: These practices help developers understand how to use your code effectively and provide helpful hints for integrated development environments (IDEs) and static analysis tools. |