카테고리 없음

Anonymous Functions : lambda function 람다함수

써니(>_<) 2022. 7. 18. 08:25

람다함수를 익명함수라고 부르는 이유 :

If you want to pass a function without previously defining and naming it, you can use a "lambda function"

 

lambda«LIST OF PARAMETERS»: «EXPRESSION»

 

global_value = 10

# a function takes function and double its return value:
def double_result(f):
	return f(global_value) * 2
    
# named function takes integer and plus one 
def plus_one(x):
 return x + 1
# call double_result with the named function as argument
double_result(plus_one)# returns 22

# same effect, but using a lambda instead of a named function
double_result(lambda x: x+1) # returns 22