We already talked about the dir function, which may come in really useful if you need to check an attribute or what’s in scope. If you need assistance with objects and their attributes, there’s the help function for you.
If you need help on a string method or on the int type in general for example, you can use the built-in help function. If you use it without any arguments, you’ll get a general message with some guidance on how to use the help function:
>>> help()
Welcome to Python 3.7's help utility!
If this is your first time using Python, you should definitely check out
the tutorial on the Internet at https://docs.python.org/3.7/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".
help>
You are now inside the help utility. You can leave it by just typing ‘quit’. But before you do it, try it out.
You can get help on particular modules, keywords, symbols or specific topics. You can also get help on particular methods. Here are some examples:
– If you need the list of keywords:
>>> help("keywords")
You can also get help on a specific keyword from the list:
>>> help("del")
Should you need the list of symbols, type:
>>> help("symbols")
or help on the random module:
>>> help("random")
For help on the float type:
>>> help(float)
And if you need help on the built-in len function:
>>> help(len)
If you need help on the split method, which is a string method:
>>> help(str.split)
And if you need help on a specific topic, you can get the list of available topics:
>>> help("topics")
and then you can choose a topic for detailed help:
help("SCOPING")
As you can see, you can get quite a lot of information from the help function. You can now leave the help utility. To do so, just type ‘quit’.
Here’s the video version: