Python3 函數 匿名函數(002)
add = lambda x, y : x + yprint(add(1, 2))#3print(add(nihao, aiqing))print((lambda x: x ** 3)(5)) #125---------------------------------------------names = [wang er, zhang zan, li si, ma zi, a b, b a]print(sorted(names, key=lambda name: name.split()[0].lower()))#[a b, b a, li si, ma zi, wang er, zhang zan]----------------------------------------------------------x = 10a = lambda y: x + yx = 20b = lambda y: x + yprint(a(10)) #30print(b(10)) #30x = 30print(a(10)) #40print(b(10)) #40-------------------------------------------------a = lambda y, x = 10: x + yb = lambda y, x =20: x + yprint(a(10)) #20print(b(10)) #20------------------------------------------------funcs = [lambda x: x+n for n in range(5)]for i in funcs: print(i(4)) #88888funcs = [lambda x, n=n: x+n for n in range(5)]for i in funcs: print(i(4)) #45678--------------------------------------------------def spam(a, b, c, d): print(a, b, c, d)spam(1, 2, 3, 4, )from functools import partialfunc = partial(spam, 1)func(2, 3, 4)funcA = partial(spam, d=2)funcA(1, 3, 4)-------------------------------------------------
推薦閱讀:
※Coq學習筆記11:策略和證明自動化
※我願意在她手掌之中(一):範式
※分享兩個python工具, 能讓你寫函數時像絲般順滑
※[公告] Idris-zh 中文翻譯項目啟動