var or inout parm?
sturlamolden
sturlamolden at yahoo.no
Fri Dec 12 08:04:12 EST 2008
On Dec 12, 1:56 pm, sturlamolden <sturlamol... at yahoo.no> wrote:
> That is because integers are immutable. When x += 1 is done on an int,
> there will be a rebinding. But try the same on say, a numpy array, and
> the result will be different:
And a consequence of this is, if you have a function like
def foobar(x):
x += 1
then the parameter x will be modified given that x have mutable type.
However, if we have a function like
def foobar(x):
x = x + 1
then x will not be modified, mutable or not.
(Well, you could abuse operator overlaoding to make unexpected side
effects in the latter case. But except for such insanity it will not
have side-effects.)
More information about the Python-list
mailing list