Why Does List Argument in Python Behave Like ByRef?
Question: This may be for most languages in general, but I'm not sure. I'm a beginner at
Python and have always worked on copies of lists in C# and VB. But in Python
whenever I pass a list as an argument and enumerate through using a "for i in
range," and then change the value of the list argument, the input values
actually changes the original list. I thought Python was supposed to pass
arguments by value by default so that once the function is finished I still
have the original values from before I called the function. What am I missing?
Thanks!


Answer: Python does pass arguments by value but the value you are receiving is a copy
of the reference (incidentally this is the exact same way that C#, VB.NET, and
Java behave as well).

This is the important thing to remember:

> _Objects are not passed by reference - object references are passed by
> value_.

Since you have a copy of the reference, any operation on what that reference
points to will be just as if you were holding the original reference itself.

