Chapter 1 of 1Lambda Functions in Python
Get the full course
Python · 0:53
Lambda functions: definition, syntax and example
Small anonymous functions.
- A lambda is a small anonymous function for quick operations.
- It can take many arguments but only one expression.
- Syntax: `lambda a, b: a + b` — call it directly or store it in a variable.
| Regular function | Lambda |
|---|---|
| def add(a, b): return a + b | add = lambda a, b: a + b |
| Named, many statements | Anonymous, one expression |
Do this in your own tools, step by step. Ticks are saved on this device.
Max expressions?
One.
Keyword?
lambda.
0:00 If we were to do this in a lambda function, we would use the keyword lambda, and after that we would give in the argument, which is A comma B. Then we would use a colon, and we would specify the expression. So, we want to add those arguments together, which is A plus B. Now, you can run this directly by wrapping this around in a print function, or you can store it in a variable like I did here called add, and then you can call this right here.
Liked chapter 1?
Get the full courseGet the other 0 chapters, the exam and your certificate for LinkedIn, plus all 700+ AI courses.