当前位置: 首页 > 工具软件 > Zatacka X > 使用案例 >

lambda x:x*x

栾耀
2023-12-01

  1. lambda x:x*x等同于
def f(x):
    return x*x


def build():
    return lambda x:x*x
等同于:
def build():
    def f(x):
        return x*x
    return f
引用
print(build()(5))    #等同于   f=build()    print(f(5))


def build(x):
    return lambda :x*x
等同于
def build(x):
    def f():
        return x*x
    return f
引用
print(build(5)())  


def build(x):
    return lambda x:x*x
等同于
def build(x):
    def f(x):
        return x*x
    return f
引用
print(build(5)(4))     #16
print(build('a')(4))    #16

 类似资料: