python函数示例
Example:
例:
Here, we are defining two function foo() and koo(), function koo() will take an argument x that will be a function while calling.
在这里,我们定义了两个函数foo()和koo() ,函数koo()会接受一个参数x ,该参数将在调用时成为函数。
The calling statement is koo(foo) - where, koo() is first function and foo() is second function. Function foo() is function as an argument here.
调用语句是koo(foo) -其中, koo()是第一个函数,而foo()是第二个函数。 函数foo()在此处用作参数 。
Code:
码:
# defining a function
def foo():
print("I am Foo")
# defining an another passing,
# it will take function as an argument
def koo(x):
x()
# calling first function by passing
# second function as an argument
koo(foo)
Output
输出量
I am Foo
翻译自: https://www.includehelp.com/python/function-as-argument-example.aspx
python函数示例