lambda x:x*x


整理自:廖雪峰的讨论区
https://www.liaoxuefeng.com/discuss/001409195742008d822b26cf3de46aea14f2b7378a1ba91000/0014582466554406b47c51ff8a44fc881529a75788f267d000

lambda 基础学习: https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001431843456408652233b88b424613aa8ec2fe032fd85a000
  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

你可能感兴趣的:(Python)