def my_function():
"""Do nothing, but document it.
No, really, it doesn't do anything.
"""
pass
让我们看看打印时的效果
^{pr2}$
docstrings声明
下面的Python文件显示了Python中docstring的声明
源文件:
"""
Assuming this is file mymodule.py, then this string, being the
first statement in the file, will become the "mymodule" module's
docstring when the file is imported.
"""
class MyClass(object):
"""The class's docstring"""
def my_method(self):
"""The method's docstring"""
def my_function():
"""The function's docstring"""
>>> help(mymodule.MyClass)
The class's docstring
>>> help(mymodule.MyClass.my_method)
The method's docstring
>>> help(mymodule.my_function)
The function's docstring
Docstring示例
让我们展示一个多行docstring示例:
让我们看看打印时的效果
^{pr2}$docstrings声明
下面的Python文件显示了Python中docstring的声明 源文件:
如何访问Docstring
下面是一个交互式会话,演示如何访问docstring
假设这是文件我的模块.py然后这个字符串,作为 导入文件时,该文件将成为mymodules modules docstring。在
相关问题 更多 >
编程相关推荐