1multiply = lambda x,y: x * y
2multiply(21, 2) #42
3#_____________
4def myfunc(n):
5 return lambda a : a * n
6
7mydoubler = myfunc(2)
8print(mydoubler(11)) #22
1Lamda is just one line anonymous function
2Useful when writing function inside function
3it can take multiple arguments but computes only one expression
4
5Syntax:
6 x = lambda arguments : expression
1>>> full_name = lambda first, last: f'Full name: {first.title()} {last.title()}'
2>>> full_name('guido', 'van rossum')
3'Full name: Guido Van Rossum'
4
1#lambda can be also used for adding string
2>>> full_name = lambda first, last: f'Full name: {first.title()} {last.title()}'
3>>> full_name('guido', 'van rossum')
4'Full name: Guido Van Rossum'
5