对于一个函数,只有一句话表示,那么就可以用lambda表达式表示,如: out: 25 可以写为: out: 25 对于多个形式参数: out: 9 lambda用到比较多的地方是排序,如: 可以写为: lambda也经常用在符合函数下,如: 345 345def f(x): return x * x print(f(5))
f = lambda x: x*x # 冒号左边为输入,右边是返回值,f是函数名 print(f(5))
g = lambda x,y: x+y # 冒号左边为输入,右边是返回值,f是函数名 print(g(4,5))
def get_four(my): return my[2] tuple_my = [] file = open("file.csv", "r") for line in file: Line = line.strip() arr = line.split(",") one = arr[1] three = arr[3] four = int(arr[4]) tuple_my.append( (one, three, four) ) tuple_my.sort(key=get_four) for my in tuple_my: print(my)
get_four = lambda my: my[2] tuple_my = [] file = open("file.csv", "r") for line in file: Line = line.strip() arr = line.split(",") one = arr[1] three = arr[3] four = int(arr[4]) tuple_my.append( (one, three, four) ) tuple_my.sort(key=get_four) for my in tuple_my: print(my)
tuple_my = [] file = open("file.csv", "r") for line in file: Line = line.strip() arr = line.split(",") one = arr[1] three = arr[3] four = int(arr[4]) tuple_my.append( (one, three, four) ) tuple_my.sort(key=lambda my: my[2]) for my in tuple_my: print(my)
def quadratic(a, b, c): return lambda x: a*x*x*x + b*x*x + c*x f = quadratic(3, -2, 4) print(f(5))
def quadratic(a, b, c): return lambda x: a*x*x*x + b*x*x + c*x print(quadratic(3, -2, 4)(5))
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算