[Numpy-discussion] augmented assignment and in-place operations
Alan G Isaac
Wed Oct 29 22:37:33 CDT 2008
On 10/29/2008 3:43 PM Robert Kern wrote:
> The defining characteristic is
> that "x <op>= y" should be equivalent to "x = x <op> y" except
> possibly for *optional* in-place semantics.
This gets at a bit of the Language Reference that I've
when possible, the actual operation is performed
in-place, meaning that rather than creating a new
object and assigning that to the target, the old
object is modified instead.
What does that mean? I assume "when possible" means in part
"when mutable", ruling out e.g. Python integers or floats.
But the rest does not really seem part of the language, but
rather seems to be normative? That is, I could define
__iadd__ anyway I want. Is the above saying that I "should"
define __iadd__ to do an in-place operation "if possible".
If so, why is such a normative statement part of the
language reference? Or is it a statement about the language
that I'm just not getting?
More information about the Numpy-discussion