lambda – create/build function in an expresssion..

Home Forums Python Programming lambda – create/build function in an expresssion..

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1957 Reply
    Humble
    Keymaster

    lambda is a wonderful feature of python which allows you to create a function without giving/referring by a name.. It make flexible coding by creating a function in an expression.. A very good use place for lambda would be returning a function call with another function..

    The general form of the lambda would be :

    lambda arg1, arg2, …argN : expression using arguments

    For ex: lambda x,y,z: x+y+z

    >>>> lambda x,y,z: x+y+z
    <function <lambda> at 0x7f2f44aa3938>
    >>> f= lambda x,y,z: x+y+z
    >>> f
    <function <lambda> at 0x7f2f44aa39b0>
    >>> f(5,7,8)
    20
    >>> 
    
    bullets to remember about lambda:
    
    lambda can be used to create a short, anonymous function. lambda does not contain return statements.. Only one expression ( which return a value) can be put inside the lambda function.
    #1967 Reply
    Humble
    Keymaster

    Lambda functions are mainly used in combination with the functions filter(), map() and reduce().

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: lambda – create/build function in an expresssion..
Your information: