Code Explanation:
Lambda Function:
lambda x, y: x * y creates an anonymous function (lambda function) that takes two arguments, x and y.
The function's body is x * y, meaning it returns the product of x and y.
Assigning to a Variable:
multiply = lambda x, y: x * y assigns the lambda function to the variable multiply.
Now, multiply can be used as a regular function.
Calling the Function:
result = multiply(4, 7) calls the multiply function with the arguments 4 and 7.
Inside the function, x becomes 4 and y becomes 7, so the return value is 4 * 7, which is 28.
Printing the Result:
print(result) outputs the value of result to the console, which is 28.
Output:
The program prints:
28
0 Comments:
Post a Comment