Background of Python - Lambda

steadycode·2022년 11월 23일
0

Python을 활용하여 코딩을 하면서 종종 Lambda 라는 키워드를 본 적이 있을 것이다. 본 글은 python에서 사용하는 lambda 라는 함수에 대해 다룬다.


Lambda

python 공식 문서에 따르면 lambda 의 정의는 다음과 같다.

Lambda expressions (sometimes called lambda forms) are used to create anonymous functions. The expression lambda parameters: expression yields a function object. The unnamed object behaves like a function object defined with:

lambda_expr ::=  "lambda" [parameter_list] ":" expression

위 정의를 쉽게 요약하자면 다음과 같다.

  • 익명 함수를 생성할 때 사용됨.
  • 표현식으로 함수 오브젝트를 생성.

example of Lambda

x + 15 of Lambda

func = lambda a : a + 15
print(func(5)) 
20

sum of parameters of Lambda

func = lambda l : sum(l)
tmp_list = [1,2,3,4,5]
print(func(tmp_list))
15
profile
steadycode

0개의 댓글