Python 代码的单元测试、打包与文档编写
1. 编写文档字符串
在 Python 编程中,所有函数、方法和类都应该有文档字符串(docstring)来描述其功能。文档字符串是紧跟在 def 语句或 class 语句之后的三引号字符串,虽然 Python 语言本身并不强制要求,但对于后续阅读、理解、扩展、改进或修复代码的人来说是必不可少的。
以下是一个更完整的类定义示例:
class Point:
"""
Point on a plane.
Distances are calculated using hypotenuse.
This is the "as a crow flies" straight line distance.
Point on a plane.
Distances are calculated using hypotenuse.
This is the "as a crow flies" straight line distance.
>>> p_1 = Point(22, 7)
>>> p_1.x
22
>>> p_1.y
7
>>> p_1
Point(22, 7)
"""
def __init__(self, x, y):
"""Create a new point
:param x: X coördi
超级会员免费看
订阅专栏 解锁全文
3万+

被折叠的 条评论
为什么被折叠?



