7554425D-0054-440D-B95E-D2ABC13D62CD Created with sketchtool.
Your Saved Info Packages

View your saved Course or Program Packages containing pricing and detailed curriculum.

Speak with a Learning Advisor.

Have any questions? We'll call you.

Fill out the form below and a Learning Advisor will reach out at a time convenient for you.

Please pick a valid date and time between 9 AM and 8 PM eastern (Monday to Friday)

By clicking "Book a call," you accept our Terms and will also receive exclusive offers and updates about new courses, workshops and events.

Python Tutorial

Python Lambda

Ready to start your career in Data? Find out more about BrainStation's Python Course

Functions in Python are defined using the def keyword and always have a name that describes what the function does. However, Python also allows developers to write functions that do not have a name. These functions are called anonymous functions and they are defined using the lambda keyword. Python Lambda Functions are also called Lambda Expressions.

Any lambda function or expression is of the following form:

lambda argument(s): function logic or expression

Python Functions vs Lambda Expressions

Let’s take a look at how Python Lambda functions or expressions differ from normal Python functions. We will take an example of a function that multiplies a number by 10:

As seen above, Python lambda functions or expressions are very useful when there is a need for an expression-like temporary function for which giving a name is not necessary. Python lambda functions or expressions are also useful when you need a function as an argument to other functions in Python. For example, functions like filter() and map() are very popular in languages like Python. filter() takes an anonymous function or lambda expression and a list as parameters and filters out all the values from the list that do not match a condition or predicate. map() on the other hand takes an anonymous function or lambda expression and a list as parameters and produces an altogether new list of values based on certain logic.

Let’s take a look at these examples:

As seen in above examples, we use lambda expressions to:

  • Make all the dog breed names in a list as plural value by using map()
  • Filter out all the grades that are less than or equal to 35 by using filter()
Set Password

You already have an account with BrainStation, but you still need to set up a password.