In python integers are immutable. v += 1
only binds a new integer value to the name v
, which is local in your function. It does not modify the integer in place.
Lists in python are mutable. You pass a list (by reference, as always in python), and the function changes it in place. That's why the change is "seen" externally to the function.
There is no such thing as "passing by value" in python.
What you probably want to do is return v+1
from your function, not to modify the value bound to the name v
.