Static variable vs Class variable

Duncan Booth duncan.booth at invalid.invalid
Wed Oct 17 07:24:45 EDT 2007


Hrvoje Niksic <hniksic at xemacs.org> wrote:

> paul.melis at gmail.com writes:
> 
>> Right, the paragraph is actually pretty clear after a second
>> reading.  I find it surprising nonetheless, as it's easy to forget
>> to return a result when you're implementing a method that does an
>> in-place operation, like __iadd__:
> 
> I've recently been bitten by that, and I don't understand the
> reasoning behind __iadd__'s design.  I mean, what is the point of an
> *in-place* add operation (and others) if it doesn't always work
> in-place?
> 
A very common use case is using it to increment a number:

   x += 1

If += always had to work inplace then this would throw an exception: an 
inplace addition would be meaningless for Python numbers.



More information about the Python-list mailing list