python lambda
multiply = lambda x,y: x * y
multiply(21, 2) #42
#_____________
def myfunc(n):
return lambda a : a * n
mydoubler = myfunc(2)
print(mydoubler(11)) #22
lambda python
nums = [1, 2, 3, 4, 5]
print(list(map(lambda n:n*n, nums)))
#lambda n : n in this case is the passed value
lambda en python
doblar = lambda num: num*2
doblar(2)
lambda in python
#multiplication using python
multiplication = lambda num, num2 : num * num2
print(multiplication(20,7))
lambda python
>>> def make_incrementor(n):
... return lambda x: x + n
...
>>> f = make_incrementor(42)
>>> f(0)
42
>>> f(1)
43
lambda python
# Lambda is what is known as an anonymous function. Basically it's like a function but a variable
# This is the "python" way of writing a lambda function
multiply = lambda x,y: x * y
# The x,y are the arguments used for the function and "x * y" is the expression
multiply(10, 10) #100
# Lambda are useful sometimes for a number of python projects.
|