Lambda function of Python function

Reminder: if the reader has not learned to defdefine functions, please read here first

Definition form

<函数名> = lambda <参数列表>: <返回值>

Equivalent to:

def <函数名>(<参数列表>):
	return <返回值>

It can also be defined as an anonymous function (function without a name):

lambda <参数列表>: <返回值>

It can be confirmed lambdathat the type of the function object is defthe same as the one defined, both function:
img

transfer

If it is an anonymous function, the call form is:

(lambda <参数列表>: <返回值>)(<参数列表>)

If not, the call form is:

<函数名>(<参数列表>)

Calculate a + b a+ba+Function of b :
a+b_img

No return value

lambdaThe function can also return no value.
For example
img
, lambdafunctions with no return value are generally used to do things , such as print('Hello World')etc.

Guess you like

Origin blog.csdn.net/write_1m_lines/article/details/105656393