This is the 14th part of this article series about Python This series was only for taking you through the very basics concepts of Python. Afterward in the second version of this article series, I'll take you through some advanced concepts.
For getting the theme of Python, kindly go through my previous articles:
- Diving Into Python: Chapter 1
- Diving Into Python: Chapter 2
- Diving Into Python: Chapter 3
- Diving Into Python: Chapter 4
- Diving Into Python: Chapter 5
- Diving Into Python: Chapter 6
- Diving Into Python: Chapter 7
- Diving Into Python: Chapter 8
- Diving Into Python: Chapter 9
- Diving Into Python: Chapter 10
- Diving Into Python: Chapter 11
- Diving Into Python: Chapter 12
- Diving Into Python: Chapter 13
Anonymous / Lambda Function
An anonymous function is a function that doesn't require any name or we can say that it can be defined without using a def keyword, unlike normal functions creation in the Python.
In Python, an anonymous function is defined using the "Lambda" keyword. That's why it is also called a Lambda function.
Example
- find_val = lambda x : x*x+2
- print (find_val(2))
Output:
Why Anonymous Functions
Now, there might be a question in your mind, what is the real use of a lambda / anonymous function in Python, since we have already general functions available (using the def keyword). Actually, in Python, we use anonymous functions when we require a nameless for a short span of time.
Anonymous functions are actually quite useful. Python supports a style of programming called functional programming where you can pass functions to other functions to do some really cool stuff.

The preceding argument may sound unfamiliar, let me explain in short. We do use an anonymous function as an argument to a higher-order function.
Let's take a close look at some example for a better understanding:
Example:
In a simple program of sorting out even numbers from a list, using the traditional function, the function name is defined using def the keyword. Have a look:
- def myfunc(x):
- return (x % 2 == 0)
- even_num = list(filter(myfunc, [1, 2, 3, 4, 5, 6, 7, 8, 9]))
- print (even_num)
Explanation
It will give you [2, 4, 6, 8] for sure.
Now let's do the same thing using an anonymous method in Python, using the lambda keyword. Have a look:

- even_num = list(filter(lambda x: x % 2 == 0, [1, 2, 3, 4, 5, 6, 7, 8, 9]))
- print (even_num)
Explanation
This method will also produce the same result.
Built-In Functions
We generally use Anonymous Functions along with some built-in functions, these are:
Let's explore them in detail.








Faizal HussainPosted Jun 7, 2015, 2:30 PM
Hai Abishek Jaiswal, Which IDE is best for python beginners
NitinPosted May 31, 2015, 4:01 AM
nice
Gopi ChandPosted May 31, 2015, 2:41 AM
14th awesome hiss by python...well done :)