Step-by-Step Explanation
1. Lambda Function Definition
double = lambda x: x * 2
lambda: This is used to create an anonymous (inline) function in Python.
lambda x: x * 2:
This creates a function that takes a single argument x and returns x * 2.
Essentially, this is equivalent to defining a standard function like this:
def double(x):
return x * 2
double =: The lambda function is assigned to the variable double.
2. Call the Lambda Function
print(double(4))
Here, the double lambda function is called with x = 4.
Computation:
4×2=8
3. Output
The computed value 8 is then passed to the print() function and displayed.
Final Output
The program will print:
8
0 Comments:
Post a Comment