I am trying to add help text to function in my python script, similar to when parentheses are opened for input() or print(). Docstrings do something similar, but isn't useful when writing the code.
See below picture for what I want. The yellow pop up text for print is something I also want to turn up for the pythagorus() function, or something similar.
I also hope to apply this to functions other than this.
Looks like you're using idle. The yellow popup you see actually is the first line of the docstring of print
. Usually idle displays the method signature (except for builtins like print
) and the fist line of the docstring, so if you want to show up something helpful there, then use helpful docstrings.
In python3 you can also use function annotations to hint the correct usage of your function.
Your sample function would actually make more sense if it would take two arguments and return a value. Then it could look something like this:
def pythagorus(a: int, b: int) -> int:
""" calculate a**2 + b**2
... usage example, etc ...
"""
return math.sqrt(a**2 + b**2)
Which would show up in idle like this: