python_匿名函数

python 的 匿名函数

语法:lambda[arg1 [,arg2,.....argn]]:expression

如下实例:

    sum = lambda arg1, arg2: arg1 + arg2

    #调用sum函数
    print "Value of total : ", sum( 10, 20 ) print "Value of total : ", sum( 20, 20 ) 

以上实例输出结果:

    Value of total : 30

    Value of total :  40

扩展: lambda 作为参数

  def test(a,b,func):
    result = func(a, b)
   return result

  func_new = input("请输入一个匿名函数:")

  num = test(12,34,func_new)

  print(num)



猜你喜欢

转载自www.cnblogs.com/zl0919/p/9135377.html
今日推荐