This metric measures the percentage of lines in a file that contain a comment or are part of a multi-line comment. Note that this metric ignores docstrings.

The percentage of comment lines should always be considered with the value for the related metric "Percentage of docstrings". For public modules, functions, classes and methods docstrings are the preferred method of documentation because the information can be inspected by the program at runtime, for example, as an interactive help system or as metadata for a function.

Having a low percentage of comments and docstrings is an indication that a file does not have sufficient documentation. Undocumented code is difficult to understand, modify, and reuse.

Add documentation to files with a low comment and docstring ratio. Use docstrings to document public modules, functions, classes and methods.

  • Wikipedia: Need for comments.
  • Python PEP 8: Comments.
  • Python for Beginners: Python Docstrings.
  • Python PEP 257: Docstring Conventions.