Explanation:
1. Variable Assignment
x = 10
A variable named x is created.
The value 10 is stored in x.
This x exists in the outer (global) scope.
2. Lambda Function Definition
f = lambda x: x + 5
This line creates an anonymous function using lambda.
lambda x: x + 5 means:
Take one input parameter x
Return x + 5
The function is stored in the variable f.
๐ Important:
The x inside the lambda is different from the x = 10 above.
It’s a local parameter, not the global variable.
Equivalent normal function:
def f(x):
return x + 5
3. Function Call
print(f(3))
The function f is called with argument 3.
Inside the lambda:
x = 3
Calculation → 3 + 5 = 8
The result 8 is passed to print().
4. Output
8

0 Comments:
Post a Comment