Make delicious recipes!

Python Dir and Help


Getting help in Python is very easy.
Two commands can be used for this:
  1. dir: If called without an argument, 'dir' returns all the names in the current scope.
    Else it returns some of the attributes of the given object, and of attributes reachable from it.

    1. For a module object:  returns the module's attributes.
    2. For a class object:    returns its attributes, and recursively the attributes of its bases.
    3. For any other object:  returns its attributes, its class's attributes, and recursively the attributes of its class's base classes.

    Objects can choose to customize default behavior of 'dir' by overriding the method __dir__

  2. help: help (command) provides help on any of the topics.


>>> dir (list)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', 
'__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__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']

# functions with underscores "_" around the names are the private helper methods

>>> help (list.extend)

extend(...)
    L.extend(iterable) -> None -- extend list by appending elements from the iterable







Like us on Facebook to remain in touch
with the latest in technology and tutorials!


Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Name:
Email: (Your email is not shared with anybody)
Comment:

Facebook comments:

Site Owner: Sachin Goyal