skip to Main Content

When I hover my mouse over the function len() in VS Code, it shows a little tooltip saying "Return the number of items in a container."

In C# I was able to add my own tooltips by typing /// above a custom function and filling in the weird comment that pops up. i.e.:

/// <summary>
/// This class does blah
/// </summary>
public class CustomClass {
   ...
}

Is there an equivalent to that for Python?

I’ve tried Googling for this, but all the questions are about how to activate function hints, not how to make your own hints for your custom functions.

2

Answers


  1. For function/class documentation, write what your function or class does in triple quotes (this is called a docstring), just after the declaration of the function or class:

    class Foo:
        """
        class documentation goes here
        """
        
        def do_something():
            """
            function documentation goes here
            """
            pass
    

    Be aware that the docstring must be on the same indentation level as the rest of the code of the function, and that it is the first thing after the function declaration.

    If you want to add documentation to your module, put a docstring at the TOP of your file.

    Login or Signup to reply.
  2. What dbollu said.
    Given that the PEP8 are rather loosely defined, I personally like to look to the numpy docstring style guide for guidance.
    https://numpydoc.readthedocs.io/en/latest/format.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search