Skip to content

请阐述什么是lambda表达式,并用代码描述lambda表达式的应用场景 #98

@Sogrey

Description

@Sogrey

lambda表达式:就是匿名函数,可以作为参数值传个函数或方法

a = [('a',1),('b',2),('c',3),('d',4)]

a_1 = list(map(lambda x:x[0],a))
a_2 = list(map(lambda x:x[1],a))
print(a_1)  ## ['a', 'b', 'c', 'd']
print(a_2)  ## [1, 2, 3, 4]

lambda表达式就是一个匿名函数,一般可以作为函数或方法的参数值使用。

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions