Python: 为什么数字从 int 变成了 float 类型?

Python: Why is the number changing from int in a float type?

据我所知,python 可以使用 int 类型的任意大数字。但是一旦 n > 512,我就会收到错误消息。 提前致谢

n = int(512)
num = int((4 ** n) / 4)

print(int(num))

我很伤心,这行得通。但是当 n > 512 我得到这个,当我 运行 程序时,为什么?:

Traceback (most recent call last):
  File "_", line 10, in <module>
    num = int((4 ** n) / 4)
OverflowError: integer division result too large for a float

Process finished with exit code 1

因为您使用的是浮点除法运算符,所以请改用整数 1 //:

>>> num = int((4 ** 512) // 4)
>>> num
44942328371557897693232629769725618340449424473557664318357520289433168951375240783177119330601884005280028469967848339414697442203604155623211857659868531094441973356216371319075554900311523529863270738021251442209537670585615720368478277635206809290837627671146574559986811484619929076208839082406056034304