Question about typing: ints/floats

Steven D'Aprano steven at
Thu Mar 4 03:18:23 CET 2010

On Wed, 03 Mar 2010 17:06:01 -0800, Chris Rebert wrote:

> But yes, internally, Python converted the int to a float before doing
> the addition.

To be precise, Python created a *new* float from the int, leaving the 
original int alone. Because ints and floats are objects, if Python 
actually converted the int to a float, this would happen:

>>> n = 1
>>> m = n
>>> x = 2.0 + n
>>> print x
>>> print n
>>> "abc"[m]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: string indices must be integers

and the world would rapidly be destroyed. Fortunately this does not 


More information about the Python-list mailing list