1

As dir() method in python3 returns all the available usable methods, is there any methods for returning documentation(explanation) of the method as string?

In case of pop() method of dictionary it should be returning the following:

class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT])

@overload def pop Possible types:
• (self: MutableMapping, k: _KT) -> _VT

• (self: MutableMapping, k: _KT, default: Union[_VT, _T]) -> Union[_VT, _T]

External documentation: http://docs.python.org/3.6/library/

Community
  • 1
  • 1

2 Answers2

2

You can access the docstring of a function using the __doc__ attribute:

➜ python
Python 3.6.4 (default, May 23 2018, 17:30:17)
Type "help", "copyright", "credits" or "license" for more information.
>>> print(dict.pop.__doc__)
D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised
Pierre
  • 1,068
  • 1
  • 9
  • 13
0

[Solved]

As the comments and the answers mentioned, either help() or doc works fine!

print(help(dict.pop))

print(dict.pop.__doc__)