Consider the below example.
Example - 1
The output is given below.
Here, changing the parameter's value doesn't propagate outside the function.
This also means that a
function receives the argument's value, not the argument itself.
This is true for scalars.
Let's apply this theory for lists.
Example - 2
The output is,
Example - 3
The output is,
Explanation:-
- If the argument is a list, then changing the value of the corresponding parameter doesn't affect the list (But variables containing lists are stored in a different way than scalars)
- But if we change a list identified by the parameter (not the parameter), the list will reflect the change.