You are currently viewing help() and dir() function in python tutorials point
Help() And Dir() Function In Python Tutorials Point

help() and dir() function in python tutorials point

Spread the love

In this article we are going to learn one important function regarding python functionality so let’s see:

What is the use of help() in python with example?

help() is basically a guide that lends a helping hand to any programmer. 

To speak technically, it is used to execute the built-in help system.

Help() And Dir() Function In Python Tutorials Point
Help() And Dir() Function In Python Tutorials Point

Syntax : help(object)

Also read : python benefit

help() takes in one parameter which is optional and the parameter is passed to get information about that particular object. It prints the module name,keywords,methods,documentation topic,class,all parameters and each parameter’s meaning.

           → Passing an object 

help(print)

Output:

Help on built-in function print in module builtins:

print(...)

    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 in python :

  •     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.

This provides help for the object print.

Output prints the use of the object, the necessary and the optional parameters to        be passed, explanation about each parameter.

→ Passing a string

help(‘def’)

When a string ‘def’ is passed as a parameter it outputs the documentation of how functions are defined.

→ Without any parameter

           help()

Welcome to Python 3.8’s help utility!

help> quit

If no parameter is passed and help() is called, Python’s help utility will open up on the console. Next command should be the object for which help is needed.To exit just type the command ‘quit’.

→ Parameter has no matching

If the parameter passed has no matching then output notifies that there is no documentation found for the mentioned object.

Also see : database in python

What Is The Use Of dir() In Python With Example?

It is a built-in function which when called returns a list. This list consists of attributes and methods of the parameter like functions, modules, strings, lists, dictionaries.

Syntax : dir({object})

The parameter is optional which takes in the object name.

dir() focuses on providing the most significant information instead of entire information.

If the parameter passed has dir() method, then it will be executed which will return the list of valid attributes.

If the object has no dir() method, the list return will have information extracted from the dict attribute.

If no parameter is passed then dir() returns the list of names in the current local scope.

Example:

>>> num = [‘one’,’two’,’three’]

>>> print(dir(num))

[‘__add__’, ‘__class__’, ‘__contains__’, ‘__delattr__’, ‘__delitem__’, ‘__dir__’, ‘__doc__’, ‘__eq__’, ‘__format__’, ‘__ge__’, ‘__getattribute__’, ‘__getitem__’, ‘__gt__’, ‘__hash__’, ‘__iadd__’, ‘__imul__’, ‘__init__’, ‘__init_subclass__’, ‘__iter__’, ‘__le__’, ‘__len__’, ‘__lt__’, ‘__mul__’, ‘__ne__’, ‘__new__’, ‘__reduce__’, ‘__reduce_ex__’, ‘__repr__’, ‘__reversed__’, ‘__rmul__’, ‘__setattr__’, ‘__setitem__’, ‘__sizeof__’, ‘__str__’, ‘__subclasshook__’, ‘append’, ‘clear’, ‘copy’, ‘count’, ‘extend’, ‘index’, ‘insert’, ‘pop’, ‘remove’, ‘reverse’, ‘sort’]

Summary :

In this article we saw Help() And Dir() Function In Python Tutorials Point so about this section you have any query then free to ask me

Name of Intern who share this Task :

Athira lonappan

Github Link : https://github.com/athira1402/Task

sachin Pagar

I am Mr. Sachin pagar Embedded software engineer, the founder of Sach Educational Support(Pythonslearning), a Passionate Educational Blogger and Author, who love to share the informative content on educational resources.

Leave a Reply