sturlamolden wrote: > On Dec 12, 1:56 pm, sturlamolden <sturlamol...@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.) > This was all thrashed out exhaustively in the still-feared call semantics thread. Yes, augmented operations work differently on mutable and immutable objects. Nothing to see here, move right along ...
regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list