Python 2.7 python函数作为参数传递给另一个函数
我不熟悉pragraming和python。这有点像我所拥有的Python 2.7 python函数作为参数传递给另一个函数,python-2.7,Python 2.7,我不熟悉pragraming和python。这有点像我所拥有的 Def some_function(): Print "stuff" Def another_function(x): running = True While running: x another_function(some_function()) 为什么第一次循环时它只打印“东西” 我读了一些关于后期绑定的文章,但不确定这是什么或者如何在我的示例中修复它 您没有传递函数,
Def some_function():
Print "stuff"
Def another_function(x):
running = True
While running:
x
another_function(some_function())
为什么第一次循环时它只打印“东西”
我读了一些关于后期绑定的文章,但不确定这是什么或者如何在我的示例中修复它 您没有传递函数,而是调用了函数并传递了它的值。所以它在你进入循环之前就打印了
东西
要在不调用函数的情况下引用函数,请关闭()
。因此,它应该是:
another_function(some_function);
然后,在另一个函数中,您必须调用该函数:
def another_function(x):
running = True
while running:
x()