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