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
1Table = lambda Table_of,Multiply_by: (Table_of*Multiply_by)
2print("3 * 9 = ",Table(3,9))
3
4def Concatinate(first_name, last_name):
5 return first_name + " " + last_name
6print("Concatinate using functions your name is:- {}".format(Concatinate("Harit","rai")))
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
1nums = [1, 2, 3, 4, 5]
2
3
4print(list(map(lambda n:n*n, nums)))
5#lambda n : n in this case is the passed value
1#multiplication using python
2multiplication = lambda num, num2 : num * num2
3print(multiplication(20,7))
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