[Tutor] More type() puzzlement

Alan Gauld alan.gauld at btinternet.com
Sun Oct 28 01:06:11 CEST 2007

"Dick Moores" <rdm at rcblue.com> wrote

>>  Hence if type(n) is already long it does not have to get converted
>> to int to accommodate something small.
> And that's not a bug?

No its expected behaviour.
If you start with a float and add an integer the result is a float.
Why should long act any different?

>>> n = 4.0
>>> n + 2

> So the largest int is 2147483647, or 2**31 - 1.
> (I know this is all obvious to most, but I still get a kick out of 
> doing it.)

Yep, exactly what sys.maxint tells you. ;-)

>>> import sys
>>> sys.maxint


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list