长整数:
没有明确定义的限制。可用地址空间的量形成实际限制。
(从this站点)。参见Numeric Types上的文档,您将看到长整数具有无限精度。在Python 2中,当它们超出其限制时,整数将自动切换到长整型:
>>> import sys
>>> type(sys.maxsize)
>>> type(sys.maxsize+1)
对于整数,我们有
maxint和maxsize:
int的最大值可以在带有sys.maxint的Python 2.x中找到。它在Python 3中删除,但sys.maxsize通常可以改用。从the changelog:
The sys.maxint constant was removed, since there is no longer a limit
to the value of integers. However, sys.maxsize can be used as an
integer larger than any practical list or string index. It conforms to
the implementation’s “natural” integer size and is typically the same
as sys.maxint in previous releases on the same platform (assuming the
same build options).
和任何对the difference(Python 2.x)感兴趣的人:
sys.maxint The largest positive integer supported by Python’s regular
integer type. This is at least 2**31-1. The largest negative integer
is -maxint-1 — the asymmetry results from the use of 2’s complement
binary arithmetic.
sys.maxsize The largest positive integer supported by the platform’s
Py_ssize_t type, and thus the maximum size lists, strings, dicts, and
many other containers can have.
sys.maxsize
An integer giving the maximum value a variable of type Py_ssize_t can take. It’s usually 2^31 – 1 on a 32-bit platform and
2^63 – 1 on a 64-bit platform.
浮动:
有float(“inf”)和float(“ – inf”)。这些可以与其他数字类型进行比较:
>>> import sys
>>> float("inf") > sys.maxsize
True