Lambda and Map() Functions in Python

Dr. Soumen Atta, Ph.D.
The Startup
Published in
3 min readJan 2, 2021

--

Lambda and map() functions in Python

This is a tutorial on lambda and map() functions in Python. Here, we will consider Python3. We start with the lambda function, and then we discuss the map() function in Python. This tutorial will help to understand the concepts of lambda and map() functions in Python.

Lambda function

At first, we will learn about the basics of the lambda function in Python. A lambda function is a simple one-line function. It doesn’t use def or return keywords. These are implicit here.

Syntax:

lambda args : exp

where args represents arguments and exp is the expression. The expression is executed and the result is returned. Note that lambda functions can have any number of arguments but only one expression.

Now, we will understand more about the Python lambda function using a few examples.

Example 1:

Let us define a lambda function that doubles the given value.

db = lambda x : 2*x

Here, exp is 2*x and args is x. Now, we call this function as follows:

db(3)

This will produce 6 as the output.

Example 2:

--

--

Dr. Soumen Atta, Ph.D.
The Startup

I am a Postdoctoral Researcher at the Faculty of IT, University of Jyväskylä, Finland. You can find more about me on my homepage: https://www.soumenatta.com/