Python Lambda Expression
In today Post we are going to discuss and Implement Python Lambda Expression. So if You don't know how to make simple calculator Project using python Check this Link Python Calculator.
Python Lambda |
Python Lambda
I know You thinking about what is Anonymous Function ?
So I am here for clearing your doubts so don't worry. Anonymous function is same as a function which are declare without mention a name. In Python we are already know that any normal function we declare in python by using def keyword . In sum of two number Program we simply use a function followed by def keyword.
Consider Following Examples to understand What is Normal function vs Anonymous Function
def add( num1 , num2 ) :
return num1 + num2
: - it's Indent that specify Our function definition starts from here .
Here def keyword is used to define a function.Here function name is add so we declare add function with two parameters followed by def keyword, and its return addition of two numbers.
Syntax of Lambda Expression is
we are create Lambda Expression By lambda Keyword
Let's check out How ?
lambda arguments : Expression
Lets create a lambda function that's take one arguments and add take a Expression and 10 in it.
a = lambda x: x+10print(a(5))
output is :
15
So let's me explain above example that's how lambda work
a is the name of lambda function.Here in starting we simply declared a add function followed by def keyword .
lambda is the name of keyword.
x is argument that's You have passed same like in add function.
x+10 is the Expression we know that lambda has only one number of expression and many number of arguments.
Now we simply call our lambda function in print statement and pass value of the x is 5 as a parameters and it has no return type.
So it's basic example of syntax of lambda function let's consider about above add function followed by def keyword and create using lambda Function or Anonymous Function.
we already know that lambda has any number of arguments .
So Let's Begin :
add = lambda a,b:a+b
print(add(50+20))
Output is - - - - -
70
So that's all for today If You Have Still any Problem Drop Your Comments Below and see you in Next Python Tutorials :)
Also Read - - Python Simple Calculator Program
Also Read - - database schema design questions
Also Read - - Java OOPS Give Your 30 Minutes
Also Read - - How Many Types of DBMS Languages ?
Also Read - - For More Education Tutorial
Follow us on Medium - - Medium
Like our Facebook Page - - Facebook Page
Follow us on Twitter - - Twitter
Contact For Any Queries - - Contact Me
1 Comments
Amazing Concepts
ReplyDeleteWrite your comments or feedback here.........