lambda () function

lambda

lambda prototype: lambda parameters: Operation (parameter)

lambda function, also called anonymous functions that do not function specific name that allows rapid definition of one-way function can be used anywhere a function is required. This differs from the definition of the function def.

lambda and def difference:

1) def method is to create the name, but no lambda.

2) lambda returns a function object, but the object is not assigned an identifier, def will assign the function object to a variable (function name).

3) lambda is just an expression, but it is def a statement.

4) lambda expression ":" back, only one expression, def you can have more.

5) if the image or the like can not be used for the print statement or the lambda, def can.

6) lambda generally used to define a simple function, and can define complex function def.

g = lambda x : x ** 2
print (g(3))

Source: https://i.cnblogs.com/EditPosts.aspx?opt=1


 

A = [3,6,1,5,4,2]
A.sort()
print(A)

Keyword Sort:

student = [['Tom', 'A', 20], ['Jack', 'C', 18], ['Andy', 'B', 51]]
student.sort(key=lambda student: student[2])
print(student)

Source: https://zhuanlan.zhihu.com/p/59702850


 

Guess you like

Origin www.cnblogs.com/yibeimingyue/p/11256517.html