Lambda is another way of creating functions. There’s nothing intimidating about it, you’re already familiar with functions. The difference is lambda defines functions inline.

There’s nothing you can do with lambda that you can’t do with a normal Python function. Lambda functions work well on collections like lists.

**Related course:** Complete Python Bootcamp: Go from zero to hero in Python

### Lambda function

Let’s start with a normal function and then create the lambda variant of it.

If we have a function like:

0 1 2 3 | def f(x): return x*x |

we can replace it with:

0 1 2 3 4 | f = lambda x: x * x y = f(4) print(y) |

You could also do:

0 1 2 3 4 | f = lambda x: x + 1 y = f(5) print(y) |

or combine it with map to apply the lambda function to each element:

0 1 2 3 4 5 | values = [1,2,3,4,5,6,7] square = lambda x: x * x squared = list(map(square, values)) print(squared) |