[Python-Dev] INPLACE_ADD and INPLACE_MULTIPLY oddities in ceval.c
Armin Rigo
arigo at tunes.org
Thu Mar 30 09:27:02 CEST 2006
Hi Tim,
On Wed, Mar 29, 2006 at 08:45:10AM -0700, Tim Hochberg wrote:
> Ouch. Assuming the same path is followed with tuples, I think that this
> means the following behaviour will continue:
>
> >>> t = (1,2,3)
> >>> a = array([4,5,6])
> >>> t += a
> >>> t
> array([5, 7, 9])
I fell into the same trap at first, but no: in fact, only lists have a
special in-place addition among all the built-in objects. Tuples fall
back to the normal addition, which means that you can only add tuples to
tuples:
>>> t = (1,2,3)
>>> t += [4,5,6]
TypeError: can only concatenate tuple (not "list") to tuple
>>> t += array([4,5,6])
TypeError: ...
This is current behavior and it wouldn't change.
A bientot,
Armin.
More information about the Python-Dev
mailing list