Is behavior of += intentional for int?
Terry Reedy
tjreedy at udel.edu
Tue Sep 1 20:00:16 EDT 2009
Steven D'Aprano wrote:
>
> I'm asking what *problem* you are trying to solve with mutable numbers,
> where immutable numbers are not satisfactory. The only answer I can
> imagine is that you're worried about the overhead of creating new integer
> objects instead of just flipping a few bits in an existing integer
> variable.
Of course, *because ints are immutable*, an implementation can avoid the
overhead of object creation for common cases by creating an array of
small integers.
CPython currently does this for -10 (or -5?) to about 256 or 257. I
would not be surprised if this coevers at least 80% of int.__new__ requests.
tjr
More information about the Python-list
mailing list