본문 바로가기
IT World/Python

Python Training Day 13. Lambda functions

by 닷라인웨이 2022. 12. 26.

Chapter 15. Lambda functions

 

Instead of defining the function somewhere and calling it, we can use python's lambda functions, which are inline functions defined at the same place we use it.

They don't need to have a name, so they also called anonymous functions. We define a lambda function using the keyword lambda.

your_function_name = lambda inputs : output

 

Exercise

l = [2,4,7,3,14,19]

for i in l:
  odd_lambda = lambda x : x % 2 != 0
  print(odd_lambda(i))
  
  
  <script.py> output:
    False
    False
    True
    True
    False
    True

댓글