A Byte of Python

Getting Help

If you need quick information about any function or statement in Python, then you can use the built-in help functionality. This is very useful especially when using the interpreter prompt. For example, run help(str) - this displays the help for the str class which is used to store all text (strings) that you use in your program. Classes will be explained in detail in the chapter on object-oriented programming.


Press q to exit the help.

Similarly, you can obtain information about almost anything in Python. Use help() to learn more about using help itself!

In case you need to get help for operators like print, then you need to set the PYTHONDOCS environment variable appropriately. This can be done easily on Linux/Unix using the env command.

$ env PYTHONDOCS=/usr/share/doc/python-docs-2.3.4/html/ python
Python 2.3.4 (#1, Oct 26 2004, 16:42:40)
[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> help('print')

You will notice that I have used quotes to specify 'print' so that Python can understand that I want to fetch help about 'print' and I am not asking it to print something.

Note that the location I have used is the location in Fedora Core 3 Linux - it may be different for different distributions and versions.