help, and dir¶As part of the Function Design Recipe, we've been writing descriptions of our functions and placing them below the function header inside triple-quoted strings. These descriptions are called docstrings, which stands for documentation strings.
The docstrings are useful to others reading our saved programs and using our code, and these descriptions can be accessed using Python's built-in function help.
Recall our function square, from earlier:
def square(num):
"""(number) -> number
Return num squared.
>>> square(5)
25
>>> square(-6)
36
"""
return num * num
In the Python shell, we can called help(square) to get the docstring description:
help(square)
We can use help and another built-in function named dir to find out more about Python's built-in functions too. Calling dir(__builtins__) produces output that includes a list of Python's built-in functions (for now, focus only on the names that are entirely lowercase):
dir(__builtins__)
Once we've found a function using dir, we can find out more about it by calling help:
help(abs)
help(round)
help¶Consider this description of built-in function ord:
help(ord)
ord have?ord's parameter(s)?ord.