python函数示例_Python | 函数作为参数的示例

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函数示例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值