【发布时间】:2019-08-05 07:26:36
【问题描述】:
我对函数的返回语句有疑问。如果函数不返回任何内容,python 标准是否说要有一个函数的 return 语句。没有什么是停下来写或不写返回,但需要知道什么是好的代码
下面是示例代码
def test():
print("Hello")
return
或
def test():
print("Hello")
在 Python 中哪种方法更传统?
【问题讨论】:
-
如果您的函数不应该返回任何内容,则不需要
return语句。你的第一个函数看起来很奇怪。 -
而且“pythogenic”并不是你想的那样。
-
@khelwood:也许我们应该使用“pythopathic”;)
标签: python conventions coding-style