Accessing Documentation with help()
A docstring is a string literal that occurs as the first statement in a module, function, class, or method definition. It is used to document what the code does. Python's built-in help() function is an excellent tool for viewing this documentation in a clean, readable format. The help() function is designed for interactive use.
Let's start by viewing the documentation for the built-in print() function.
First, open a terminal in the WebIDE. You can do this by clicking the Terminal menu at the top of the screen and selecting New Terminal.
In the terminal, start the Python interactive shell by typing the following command and pressing Enter:
python
You will see the Python prompt (>>>). Now, use the help() function to get information about print():
help(print)
The terminal will display the documentation for the print function.
Help on built-in function print in module builtins:
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
(END)
This output explains what the function does, what parameters it accepts, and their default values. Press the q key to exit the help viewer and return to the Python prompt.
Now, exit the Python interactive shell by typing:
exit()