Python中备注的使用

2019-06-01  本文已影响0人  DingDingYuan

单行备注:

# 井号之后的代码都不会被执行
a=1 # 这里是单行备注,不会被执行

多行备注

"""
这里面无论加什么都不会执行
随便加
rm -fr /*
I love you all!
I hate you all!
"""
# 
a= 1

同时备注多行:
选择多行然后,普通键盘:control+/;Mac键盘: Command+/


gif_toggle.6424d45ed925.gif

函数与函数包的Doc文件

def sparsity_ratio(x: np.array) -> float:
    """Return a float

    Percentage of values in array that are zero or NaN
    """

以上文字将成为.doc的一部分

# -*- coding: utf-8 -*-
"""A module-level docstring

Notice the comment above the docstring specifying the encoding.
Docstrings do appear in the bytecode, so you can access this through
the ``__doc__`` attribute. This is also what you'll see if you call
help() on a module or any other Python object.
"""

参考
https://realpython.com/python-comments-guide/
https://www.python.org/dev/peps/pep-0257/#one-line-docstrings

上一篇 下一篇

猜你喜欢

热点阅读