Step-by-Step Explanation:
1. def add_five(n):
-
A function add_five is defined that takes a single parameter n.
2. n += 5
-
Inside the function, n is increased by 5.
-
However, n is a local variable (a copy of the original value).
-
Since n is an integer (an immutable type in Python), modifying it inside the function does not affect the original variable.
3. value = 10
-
A variable value is set to 10.
4. add_five(value)
-
The value 10 is passed to the function.
-
Inside the function, n = 10, and it becomes 15, but only inside the function.
-
The original variable value remains unchanged.
5. print(value)
-
It prints the original value, which is still 10.
✅ Final Output:
Key Concept:
-
Integers are immutable in Python.
-
Reassigning n inside the function does not change value outside the function.


0 Comments:
Post a Comment