lambda function in python

is used to create function without name(annonymous function). its one line function

 syntax:

lambda p1,p2,p3...pn :expression

you can read ':' as 'such that' as  in set builder method 

note:

p1,p2...pn = function parameters

there can be only one expression

lambda function by itself  returns  a function object

example

sum=lambda a,b:a+b

print(sum(1+2))
output 
3

x=1
print(lambda x :  print(x))
output:
<function <lambda> at 0xsomeaddress>

we need to call function object to get result 

IIFE stands for immediately invoked function execution
syntax::
(lambda parameter: expression)(argument)
example>>
(lambda x :  print(x**2))(9)

note:
lambda function is treated as normal function by python interpreter


Comments

Popular posts from this blog

sxhkd volume andbrightness config for dwm on void

fix idm integration on chrome

Hidden Wiki