Code Explanation:
cube = lambda x: x ** 3:
This defines a lambda function (an anonymous function) and assigns it to the variable cube.
The lambda function takes one argument, x.
The body of the function calculates the cube of x using the exponentiation operator ** (raising x to the power of 3).
result = cube(3):
This calls the cube lambda function with the argument 3.
The lambda function computes 3 ** 3, which is 27.
print(result):
This prints the value stored in the variable result, which is 27.
Output:
27
0 Comments:
Post a Comment