use*_*653 11 function python-2.7 spyder
我最近开始使用Python编程.我必须编写许多函数,并且想知道如何合并一个帮助或描述文本,以便在调用函数时它出现在spyder的对象检查器中.在MatLab中,这通过将注释文本放在函数文件的开头来工作.Python中是否有类似的方法(使用Spyder)?
Bur*_*lid 26
默认情况下,方法体中的第一个字符串用作其docstring(或文档字符串).当help()
为该方法调用时,Python将使用它.
def foo(bar):
''' Takes bar and does
some things to it '''
return bar
help(foo)
foo(bar)
Takes bar and does
some things to it
Run Code Online (Sandbox Code Playgroud)
您可以通过阅读PEP-258阅读有关其工作原理的更多信息,此问题将详细介绍.
简短回答一下。这可以通过将文本放在三引号之间来完成。
'''
@param self
'''
Run Code Online (Sandbox Code Playgroud)
您可以在此链接上找到一个简短的示例:https://www.jetbrains.com/help/pycharm/creating-documentation-comments.html#
其他答案更广泛。