整数和数字的区别.Python中的整数

2024-04-26 12:14:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图对Python的数据模型有更深入的了解,但我不完全理解以下代码:

>>> x = 1

>>> isinstance(x,int)
True

>>> isinstance(x,numbers.Integral)
True

>>> inspect.getmro(int)
(<type 'int'>, <type 'object'>)

>>> inspect.getmro(numbers.Integral)
(<class 'numbers.Integral'>, <class 'numbers.Rational'>, <class 'numbers.Real'>,
 <class 'numbers.Complex'>, <class 'numbers.Number'>, <type 'object'>)

基于以上,似乎intnumber.Integral不在同一层次结构中。

从Python参考(2.6.6)中我看到

numbers.Integral - These represent elements from the mathematical set of integers (positive and negative).

intnumbers.Integral有什么区别?这是否与我在上面的输出中看到的type intclass numbers.Integral有关?


Tags: 代码trueobjecttype数据模型realclassint