将参数传递给Python中的另一个函数? [英] Passing functions with arguments to another function in Python?

查看:140
本文介绍了将参数传递给Python中的另一个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



说一下类似的东西:



< pre $ def执行(函数):
函数

但是要传递的函数将如下所示:

  Action1()
Action2(p)
Action3(p,r)


解决方案



  def perform(fun,* args):
fun(* args)

def action1(args):
something

def action2(args):
something

执行(action1)
执行(action2, p)
执行(action3,p,r)


Is it possible to pass functions with arguments to another function in Python?

Say for something like:

def Perform ( function ) :
    function

but the functions to be passed will be like:

Action1()
Action2(p)
Action3(p,r)

解决方案

Do you mean this?

def perform( fun, *args ):
    fun( *args )

def action1( args ):
    something

def action2( args ):
    something

perform( action1 )
perform( action2, p )
perform( action3, p, r )

这篇关于将参数传递给Python中的另一个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆