1.2.4.7 Docstrings
关于函数作用及参数的文档。通常惯例:
In [24]:
def funcname(params):
"""Concise one-line sentence describing the function.
Extended summary which can contain multiple paragraphs.
"""
# 函数体
pass
funcname?
Type: function
Base Class: type 'function'>
String Form: <function funcname at 0xeaa0f0>
Namespace: Interactive
File: <ipython console>
Definition: funcname(params)
Docstring:
Concise one-line sentence describing the function.
Extended summary which can contain multiple paragraphs.
注 Docstring 指导
为了标准化,Docstring 惯例页面为Python Docstring相关的含义及惯例提供了文档。
Numpy和Scipy模块也为科学计算函数定义了清晰的标准,你可能想要在自己的函数中去遵循,这个标准有参数部分,例子部分等。见http://projects.scipy.org/numpy/wiki/CodingStyleGuidelines#docstring-standard 及 http://projects.scipy.org/numpy/browser/trunk/doc/example.py#L37