Python Anonymous Parameters

Source: Internet
Author: User

# -*-coding:utf-8-*- # Anonymous Functions # anonymous function syntax format " " variable = lambda parameter list: expression " "  Lambda x,y:x+= func (2,3)print(a)# an anonymous function is similar to a macro definition in C, and can only perform some simple calculations # Unlike normal functions, anonymous functions can return operation results even if there is no return keyword
#-*-coding:utf-8-*-#The application of anonymous function in the sort () function" "python is usually a line to write all the code, if you encounter a line to write the case, there are two ways: 1. At the end of the line of code, add the continuation line "\" (that is, the space +\); test = ' item_one ' item_two ' Tem_three ' Output: ' Item_oneitem_twotem_three ' 2. Parentheses, no special line breaks are required in () {} []: Test2 = (' csdn ' cssdn ') output: csdn cssdn" "Stu= [{"name":"Tom"," Age": 15},{"name":"Jack"," Age": 13},{"name":"Li"," Age": 12}]#The x here is every element in the list.#key = lambda ... This is a fixed notation, the variable name must use the key, the other variable name does not work#The key here is essentially specifying the parameter name to pass the argumentStu.sort (aa =Lambdax:x["name"])Print(Stu)
# -*-coding:utf-8-*- # function pointers such as anonymous functions assign values def Compute (A, B, func):         return func (A, b) Print Lambda x,y:x+"Lambda x,y:x*y"#eval () function can convert a string into an expression Pcmd = eval (strcmd)printLambda x,y:x*y))

Python Anonymous Parameters

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.