3: Getting Help

Book ref: Project 1 (pg 24ff)

Python 2.7: Same

See also: Python 3/Project 4 post

Python 3 comes with its own help facility. To use it, you simply type:

>>> help()

Welcome to Python 3.4's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.4/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

Note: you have to include the brackets help(). Just help won’t work:

>>> help
Type help() for interactive help, or help(object) for help about object.

As the text says, once you’re in the help service. To leave you type quit and press Enter.

You can get help on a specific feature by typing that feature at the help> prompt. If I type print and press Enter it tells me:

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.

On my system, this is not printed below the Python prompt. Rather, it is specially formatted (by a thing called a “pager”). To get back to the help> prompt I have to press the Q key.

The next place to look for help is in Python’s online documentation. That may be a little intimidating at the moment, but just go to it slowly. You’ll start to learn your way around it. One of the problems with learning Python 3 is that it is being continuously improved, so with each new version (I have version 3.4 installed, but the most recent version as at the time I am writing this is version 3.6) the documentation changes. Ideally, you’ll chose the version of the documentation that matches the version of Python you have installed on your computer. The good news is that for the stuff you’re learning things are unlikely to change for the foreseeable future.

Python 2.7 Notes: the same help facility is in Python 2.7.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: