Skip to content

help() and dir() function in Python

  • by

Python help() function returns the Python documentation of a particular object, method, attributes, etc and dir() shows a list of attributes for the object passed in as an argument.

  • dir() Returns all functions that are available in a particular Module
  • help() Gives the information about the function in that particular Module

help() and dir() function in Python

Simple example code.

help(print())
dir(print())

Output:

help() and dir() function in Python

Difference between dir() and help() functions

help() is a super useful built-in function that can be used to return the Python documentation of a particular object, method, attributes, etc.

my_list = []
help(my_list.append)
Help on built-in function append:

append(object, /) method of builtins.list instance
    Append object to the end of the list.

dir() shows a list of attributes for the object passed in as an argument, without an argument it returns the list of names in the current local namespace.

my_list = []
print(dir(my_list))
['__add__', '__class__', '__class_getitem__', '__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']

Do comment if you have any doubts or suggestions on this Python function topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *