Why does help(42) work but neither help("") nor help("x")?

python, python-2.7

Solution

See the documentation on the help function:

If no argument is given, the interactive help system starts on the interpreter console. If the argument is a string, then the string is looked up as the name of a module, function, class, method, keyword, or documentation topic, and a help page is printed on the console. If the argument is any other kind of object, a help page on the object is generated.

In other words, when `help` is given a class or type, it returns help on that class or type.

class C: pass
help(C)

When `help` is given any instance other than a string, like `help(1)`, it provides documentation on the type of that variable (`int`, `float`, or a defined class).

help(1)
help(C())

When it is given a string, it provides documentation on the type or class that that string refers to. If you want help with the `str` class itself, you can do:

help(str)

or

help("str")

Problem

Possible Duplicate: Inconsistency in python help(‘string’) versus help(list)? In the interactive shell of Python, if I type `help(42)` I get all the information about int objects. If I type `help("")` I get nothing and if I type `help("x")` I get "no Python documentation found for 'x'". I know I can type `help(str)`, but I'd like to understand why are the other two working differently from `help(42)`?

Original source