不返回任何内容时的文档字符串 [英] Docstrings when nothing is returned
本文介绍了不返回任何内容时的文档字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当函数不返回任何内容时,文档字符串约定是什么?
例如:
def f(x):"""打印作为输入给出的元素参数:x:任何元素返回:"""打印您的输入是 %s" % x返回
我应该在文档字符串中的 Returns:
之后添加什么?现在什么都没有?
解决方案
您应该使用 None
,因为这就是您的函数实际返回的内容:
"""打印作为输入给出的元素参数:x:任何元素返回:没有任何"""
Python 中的所有函数都返回东西.如果你没有明确返回一个值,那么默认情况下它们将返回 None
:
What is the docstring convention when a function doesn't return anything?
For example:
def f(x):
"""Prints the element given as input
Args:
x: any element
Returns:
"""
print "your input is %s" % x
return
What should I add after Returns:
in the docstring? Nothing as it is now?
解决方案
You should use None
, as that is what your function actually returns:
"""Prints the element given as input
Args:
x: any element
Returns:
None
"""
All functions in Python return something. If you do not explicitly return a value, then they will return None
by default:
>>> def func():
... return
...
>>> print func()
None
>>>
这篇关于不返回任何内容时的文档字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文