24、Python 代码的单元测试、打包与文档编写

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值