Question about typing: ints/floats

Wells thewellsoliver at
Thu Mar 4 00:45:51 CET 2010

This seems sort of odd to me:

>>> a = 1
>>> a += 1.202
>>> a

Indicates that 'a' was an int that was implicitly casted to a float.

>>> a = 1
>>> b = 3
>>> a / b

This does not implicitly do the casting, it treats 'a' and 'b' as
integers, and the result as well. Changing 'b' to 3.0 will yield a
float as a result (0.33333333333333331)

Is there some way to explain the consistency here? Does python
implicitly change the casting when you add variables of a different
numeric type?

Anyway, just  curiosity more than anything else. Thanks!

More information about the Python-list mailing list