且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

lambda和常规函数之间的python有什么区别?

更新时间:2022-12-13 23:34:47

它们是相同的类型,因此它们的处理方式相同:

They are the same type so they are treated the same way:

>>> type(a)
<type 'function'>
>>> type(b)
<type 'function'>

Python还知道b被定义为lambda函数,并将其设置为函数名称:

Python also knows that b was defined as a lambda function and it sets that as function name:

>>> a.func_name
'a'
>>> b.func_name
'<lambda>'

换句话说,它影响了该函数将获得的名称,但是就Python而言,两者都是函数,这意味着它们大多数都可以以相同的方式使用.有关酸洗的功能和lambda函数之间的重要区别,请参见下面的mgilson评论.

In other words, it influences the name that the function will get but as far as Python is concerned, both are functions which means they can be mostly used in the same way. See mgilson's comment below for an important difference between functions and lambda functions regarding pickling.