Comparison between Python and C # lambda expressions

Source: Internet
Author: User

Lambda expressions in Python are very simple,

Lam = lambda a: a * 2 --> lam (3) 6

It is quite useful in some cases. But it is not powerful enough to compare C # To lambda expressions (I am not in the dark python, let alone ).

 

The lambda expressions in C # are very easy to use. Anyone who has used them will feel the same. It is actually an anonymous function. As long as a common function can do things, it can do it, but it is very simple.

Form. click + = (x, y) => {
Y = y. split ('/') [0]; x. Text = y ;}

 

In Python, lambda expressions can only have one line of expressions, rather than a complete function like C. And it must return a value. Otherwise, an error is returned.

Class Form: def Click (self): return lambda x, y: x. text = yclass Label: def Textlabel = Label () form = Form () form. click (label, 'name') print label. text

Execution result

File "/home/linh/project/python/learn/test1.py", line 3 return lambda x, y: x. Text = y ^ SyntaxError: invalid syntax

Well, I feel like I am using black 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.