Python中的lambda函數

今天在看書的時候,看到了這樣的一條語句:express

if isinstance(value,int) or isinstance(value,float):
    split_function=lambda row:row[column]>=value 

對其中的lambda這個函數表示很不明白,因而看了看Python文檔,文檔中解釋以下:函數

  lambda
An anonymous inline function consisting of a single expression which is evaluated when the function is called. The syntax to create a lambda function is lambda [arguments]: expression
lambda函數也叫匿名函數,即,函數沒有具體的名稱,而用def建立的方法是有名稱的。
lambda容許用戶快速定義單行函數,固然用戶也能夠按照典型的函數定義完成函數。lambda的目的就是簡化用戶定義使用函數的過程。
例如:
log2=lambda x:log(x)/log(2)

就是定義了一個以2爲底的對數函數。這個例子是有參數的,還有一種狀況是沒有參數的:this

>>>bar=lambda :'this is a bar'
>>>print bar
this is a bar
相關文章
相關標籤/搜索