Lambda Expressions in Python

Source: Internet
Author: User

A lambda expression is an anonymous function that is used primarily for short and once, where all functions without a lambda must have a name, that is, the function is declared well before it is called.

Let's look at how lambda is used in Python.

    • Single Lambda
""if__name__"__main__":     Lambda x:x +    print(f (1))>>>43>>>
    • Multiple lambda
Function_pool = [lambda x:x + 1,                 Lambda x:x + 2]if__name__ c8> "__main__":    print(function_pool[0)     Print(function_pool[1] ())>>>4344>>>
    • Returns a lambda function
  " python 3.4return a Lambda object  Span style= "COLOR: #800000" "" " def   Make_ Incrementor (n):  return  lambda  x:x +  n  if  __name__  = =  "  __main__   " : F  = Make_incrementor (42 )  #  now f = Lambda x:x +  print   (f (0))  print  (F (1 >>>4243>>> 

Lambda expressions in Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.