Python (anonymous function)

Source: Internet
Author: User

Anonymous Functions

Anonymous functions: A sentence function designed to address the simple requirements of functions

# this piece of code def Calc (n):     return n**nprint(calc# to anonymous function lambda n:n** N Print (Calc (10))

Above is our analysis of this anonymous function of Calc, and here is a description of the anonymous function format

Lambda parameters: Return value # arguments can have multiple, separated by commas # Anonymous functions No matter how complex the logic, can only write one line, and the end of the logical execution of the content is the return value # The return value can be any data type as well as a normal function

As we can see, anonymous functions do not really have names.

There is no difference between the invocation of an anonymous function and a normal invocation. is the function name (parameter) can be.

Python (anonymous function)

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.