0 votes
in Python by
Explain the use of “help()” and “dir()” functions.

1 Answer

0 votes
by
One of the most common question in any Python interview question and answers guide. In Python, the help() function is used for showing the documentation of modules, classes, functions, keywords, and so on. If the help() function receives no parameter, it launches an interactive help utility on the console.

The dir() function is used to return a valid list of attributes and methods of the object it is called upon. Since the function aims to produce the most relevant data (instead of showing the complete information), it behaves differently with different objects:

For modules/library objects, the dir() function returns a list of all attributes contained in that module.

For class objects, the dir() function returns a list of all valid attributes and base attributes.

When no parameters are passed to it, the dir() function returns a list of attributes in the current scope.
...