1.2.4.7 Docstrings

关于函数作用及参数的文档。通常惯例:

In [24]:

  1. def funcname(params):
  2. """Concise one-line sentence describing the function.
  3. Extended summary which can contain multiple paragraphs.
  4. """
  5. # 函数体
  6. pass
  7. funcname?
  1. Type: function
  2. Base Class: type 'function'>
  3. String Form: <function funcname at 0xeaa0f0>
  4. Namespace: Interactive
  5. File: <ipython console>
  6. Definition: funcname(params)
  7. Docstring:
  8. Concise one-line sentence describing the function.
  9. Extended summary which can contain multiple paragraphs.

注 Docstring 指导

为了标准化,Docstring 惯例页面为Python Docstring相关的含义及惯例提供了文档。

Numpy和Scipy模块也为科学计算函数定义了清晰的标准,你可能想要在自己的函数中去遵循,这个标准有参数部分,例子部分等。见http://projects.scipy.org/numpy/wiki/CodingStyleGuidelines#docstring-standardhttp://projects.scipy.org/numpy/browser/trunk/doc/example.py#L37