python函数示例
Example:
例:
Here, we are defining two function foo() and koo(), function koo() will return as a value (return value of the function).
在这里,我们定义了两个函数foo()和koo() ,函数koo()将作为值返回(函数的返回值)。
The calling statement is x=koo() - where, koo() is first function and the return value of koo() (that is the function foo()) will store in the x (which is also a function).
调用语句为x = koo() -其中, koo()是第一个函数,而koo()的返回值(即函数foo() )将存储在x (也是一个函数)中。
Code:
码:
# defining a function
def foo():
print("I am Foo")
# defining an another function
# it will return function as a return value
def koo():
return foo
# function calling and assigning return value
# in x
x=koo()
x()
Output
输出量
I am Foo
翻译自: https://www.includehelp.com/python/function-as-return-value-example.aspx
python函数示例