Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Python lambda
Next article icon
Prerequisites:Python lambdaIn Python, anonymous function means that a function is without a name. As we already know the def keyword is used to define the normal functions and the lambda keyword is used to create anonymous functions. When we use lambda function inside another lambda function then it is calledNested Lambda Function.Example 1:Python3
# Python program to demonstrate# nested lambda functionsf=lambdaa=2,b=3:lambdac:a+b+co=f()print(o(4))
Output:
9
Here, when the object o with parameter 4 is called, the control shift to f() which is caller object of the whole lambda function. Then the following execution takes place-
  • The nested lambda function takes the value of a and b from the first lambda function as a=2 and b=3.
  • It takes the value of c from its caller object o which passes c = 4.
  • Finally we get the output which is the summation of a, b and c that is 9.
Example 2:Python3
# Python program to demonstrate# nested lambda functionssquare=lambdax:x**2product=lambdaf,n:lambdax:f(x)*nans=product(square,2)(10)print(ans)
Output:
200
In the above example, when the product function is called square function gets bound to f and 2 gets bound to n which then returns a function which is bound to the product which when called with 10, x is assigned this and square is called, which returns 100 and this, in turn, is multiplied with n which is 2. So it'll finally return 200.

Improve
Article Tags :
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp