Code Skiller logoCB Logo
Logo LearnLearnLogo PracticePracticeLogo HireHireLogo IDEIDE

What are Lambda Functions

User image

Published by

sanya sanya

Published at: 13th Aug, 2023
1.12 mins read

Lambda functions, also known as anonymous functions, are a powerful and versatile feature of the Python programming language. They allow you to create small, anonymous functions on the fly, without the need for a separate definition. In this blog, we will explore what lambda functions are, how they work.

At its simplest, a lambda function is a function without a name. Instead of defining a function using the def keyword and giving it a name, you can define a lambda function using the lambda keyword and pass it as an argument to another function, or use it in place of a named function in your code.

The lambda function is shorter and more concise, and it does the same thing as the named function.


For now just have a look over a what Lamba Function does :

Consider an example where we need to print the square of a number. Now instead of creating a function for printing the square we can use the lambda function to do the same.

x = lambda a : a*a print(x(5)) #printing square of 5 print(x(7)) #printing square of 7 print(x(10)) #printing square of 10 print(x(3)) #printing square of 3

Output

25
49
100
9

In conclusion, lambda functions are a powerful and flexible tool for writing concise, functional-style code in Python.

Library

WEB DEVELOPMENT

FAANG QUESTIONS

On this page