Hello @oliveiraph17 , from programming perspective,
because when Python passes a variable to a function, it does not create a new copy of the data of that variable, so modifying the data inside the function will change that data everywhere because there is always only one single copy of that data. This can be bad. To avoid this, we make a new copy and only modify the new copy inside the function so it will not affect the outside world. A nice stackoverflow discussion here.
I think the best practice is we should do the same for both w_in
and b_in
when we want to modify them inside the function without affecting the rest of the world.
It is ok that the variable w_in
is not used later on, because the content of it has been copied to w
. Remember we make a copy because we do not want to change anything in w_in
.
However, the real problem is, if you look at the highlighted line
w
is later on reassigned to w_in
which means the effect of making a new copy has gone! we are still modifying the w_in
because now both w
and w_in
points to the same data.
Having said that, is this a problem in this particular exercise?
No. Because our code in the outside world does not need to preserve the w_in
value. Also we need to do copy.deepcopy
when the variable is, for example, a numpy
array, a pandas
dataframe or complex objects like that. In our case, w_in
is merely a int
which needs not to be worried about.