Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

What is Python Lambda Function? Python Tutorial | Edureka


Published on

YouTube Link:
** Python Certification Training: **
This Edureka PPT on 'Python Lambda' is to educate you about the Lambda functions of Python and help you understand how to use them in various scenarios. Below are the topics covered in this PPT:
What are Python Lambda functions?
Why are they used?
How to write anonymous functions?
Lambda functions within user-defined functions
Using Anonymous functions within
- filter()
- map()
- reduce()
Solving algebric expressions using Lambda

Follow us to never miss an update in the future.

Published in: Technology
  • Login to see the comments

What is Python Lambda Function? Python Tutorial | Edureka

  1. 1. ❖ What are Python Lambda functions? ❖ Why are they used? ❖ How to write Anonymous functions? ❖ Lambda functions within user defined functions • filter() • map() ❖ Using Anonymous functions within • reduce() ❖Solving Algebraic expressions using Lambda
  2. 2.
  3. 3. PythonLambda Functionsare: • Anonymousornameless functions • ‘lambda’isnotaname,butitsakeyword
  4. 4.
  5. 5. Also known as throw- away functions as they are needed just once They are also passed as inputs or returned as outputs of other higher-order functions The body of Lambda functions is written in a single line One-time use I/O of other functions Reduce code size Why are they used?
  6. 6.
  7. 7. A Lambda function is created using the lambda operator lambda arguments: expression lambda : “Specify the purpose” lambda a1…n: “Specify use of a1…n“ lambda a1: “Specify use of a1“ SYNTAX:
  8. 8.
  9. 9. Lambda functions are best used within other higher- order functions Anonymous functions within user defined functions def new_func(x): return(lambda y: x+y) t=new_func(3) u=new_func(2) print(t(3)) print(u(3))
  10. 10.
  11. 11. filter() Used to filter the given iterables(lists, sets, etc) with the help of another function passed as an argument to test all the elements to be true or false. my_list = [2,3,4,5,6,7,8] new_list = list(filter(lambda a: (a/3 == 2), my_list)) print(new_list)
  12. 12. map(): Applies a given function to all the iterables and returns a new list. my_list = [2,3,4,5,6,7,8] new_list = list(map(lambda a: (a/3 != 2), li)) print(new_list)
  13. 13. reduce(): Applies some other function to a list of elements that are passed as a parameter to it and finally returns a single value. from functools import reduce reduce(lambda a,b: a+b, [23,21,45,98])
  14. 14.
  15. 15. Copyright © 2017, edureka and/or its affiliates. All rights reserved.
  16. 16.