Ric*_*son 22 python return docstring function
当函数没有返回任何内容时,docstring约定是什么?
例如:
def f(x):
"""Prints the element given as input
Args:
x: any element
Returns:
"""
print "your input is %s" % x
return
Run Code Online (Sandbox Code Playgroud)
Returns:在docstring中我应该添加什么?没有现在的样子?
iCo*_*dez 28
您应该使用None,因为这是您的函数实际返回的内容:
"""Prints the element given as input
Args:
x: any element
Returns:
None
"""
Run Code Online (Sandbox Code Playgroud)
所有的Python函数返回的东西.如果您没有显式返回值,那么它们将None默认返回:
>>> def func():
... return
...
>>> print func()
None
>>>
Run Code Online (Sandbox Code Playgroud)