0

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?

ameed
  • 1,132
  • 6
  • 25
tygzx
  • 1
  • 1
  • Why are you concerned by this, just for curiosity? There is no distinction in python 3; there is a [PEP](https://www.python.org/dev/peps/pep-0237/) that explains both why you get the result you get and how the types are unified. – roganjosh Jun 02 '18 at 10:40
  • See https://stackoverflow.com/questions/2104884/how-does-python-manage-int-and-long – kjaquier Jun 02 '18 at 10:40

1 Answers1

1

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?.

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
  • I misunderstand the meaning of int function. I think his role is conver other types to int . when i see the docs i find it would return a long object if arguments outside the integer range. thanks – tygzx Jun 02 '18 at 13:23