This is my code:
In [2]: a = 11111111111111111111111111
In [3]: a = (int)(a)
In [4]: type(a)
Out[4]: long
In [5]: a = int(a)
In [6]: type(a)
Out[6]: long
Why, after I call int
on a
, is its type still long
and not int
?
This is my code:
In [2]: a = 11111111111111111111111111
In [3]: a = (int)(a)
In [4]: type(a)
Out[4]: long
In [5]: a = int(a)
In [6]: type(a)
Out[6]: long
Why, after I call int
on a
, is its type still long
and not int
?
From the docs:
class int(x=0)
class int(x, base=10)[...] If the argument is outside the integer range, the function returns a long object instead.
With PEP 237, ints and longs were mostly unified. There is little difference between the two types and python automatically converts big numbers to long when necessary. See also How does Python manage int and long?.