Translation Notice
This article was machine-translated using DeepSeek-R1.
- Original Version: Authored in Chinese by myself
- Accuracy Advisory: Potential discrepancies may exist between translations
- Precedence: The Chinese text shall prevail in case of ambiguity
- Feedback: Technical suggestions regarding translation quality are welcomed
Note: If the reader hasn’t learned about functions defined with def
, please refer to here first
Definition Syntax
|
|
Equivalent to:
|
|
Can also be defined as anonymous function (nameless function):
|
|
We can confirm that lambda
function objects have the same type (function
) as those defined with def
:
Invocation
For anonymous functions, the invocation form is:
|
|
For named functions:
|
|
Function to calculate $a+b$:
No Return Value
lambda
functions can also have no return value.
Example:
Lambda functions without return value are generally used for performing actions, such as print('Hello World')
etc.