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.