深入理解document & comment in Python

  • Overview

    Code is more often read than written — Guido Van Rossum

    In general, commenting is describing your code to developer(code tells you how, Comments tell you why);

    Documentinig code is describing its use and functionality to your users.

  • Commenting Code

  • Basics of Commenting Code

    Comments are created in Python using the pound sign (#);

    According to PEP8, comments should have a maximum length of 72 characters.

    Following four essential rules suggested by Jeff Atwood:

    1. Keep comments as close to the code being described as possible;
    2. Don’t use complex formatting;
    3. Don’t include redundant information;
    4. Design your code to comment itself;
  • Commenting Code via Type Hinting
  • Documenting Your Code Using Docstrings

    The strategic placement of the string literal direclty below the object will automatically set the __doc__ value.

    Docstring conventions are described within PEP257.

    The docstring should use the triple-double quote (""") string format.

    Multi-lined docstrings are used to further elaborate on the object beyond the summary. All multi-lined docstrings have the following parts:

    • A one-line summary line
    • A blank line proceeding the summary
    • Any further elaboration for the docstr
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值