【发布时间】:2015-06-02 11:23:40
【问题描述】:
我正在阅读 this tutorial,在 Returning Functions 部分下,有一个类似下面的示例:
def parent(n):
def child1():
return "Printing from the child1() function."
def child2():
return "Printing from the child2() function."
if n == 10: return child1
else: return child2
作者提到返回函数中不应该有括号,但没有给出任何详细解释。我相信这是因为如果添加了括号,那么该函数将被调用,并且以某种方式将丢失流。但我需要一些更好的解释才能更好地理解。
【问题讨论】:
-
I believe that it is beacause if parenthisis are added, then the function will get called- 你是对的 -
是的,我认为它是这样工作的,但我相信更好的解释对每个人都有好处,尤其是初学者。