Code Explanation:
1.square = lambda x: x ** 2
A lambda function is an anonymous (nameless) function in Python.
Here, lambda x: x ** 2 defines a function that takes one input x and returns the square of x.
The square variable is assigned this lambda function, so square(x) can now be used like a regular function to compute
𝑥2.
2.result = square(6)
The lambda function is called with the argument 6.
Inside the lambda function, 6 ** 2 is computed, which is
6×6=36.
The result, 36, is assigned to the variable result.
3. print(result)
This prints the value of the variable result, which is 36.
Output:
36
0 Comments:
Post a Comment