Explanation:
1. Assign x = 10
x = 10
A variable x is created and assigned the value 10.
x → 10
2. Create the Lambda Function
f = lambda a=x: a
Here, a lambda function is created and stored in f.
The important part is:
a=x
This gives parameter a a default value.
At the moment the lambda is created, x is 10.
So Python effectively stores:
f = lambda a=10: a
Therefore:
f() → 10
3. Change x
x = 20
Now x is changed from 10 to 20.
x → 20
However, this does not change the default value already stored inside the lambda.
The lambda still has:
a → 10
4. Call the Lambda
print(f())
f() is called without providing a value for a.
Therefore, Python uses the stored default value:
a → 10
So:
f() → 10
5. print() Displays the Result
The expression becomes:
print(10)
✅ Final Output
10

0 Comments:
Post a Comment