我试图对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'>)
基于以上,似乎int
和number.Integral
不在同一层次结构中。
从Python参考(2.6.6)中我看到
numbers.Integral - These represent elements from the mathematical set of integers (positive and negative).
int
和numbers.Integral
有什么区别?这是否与我在上面的输出中看到的type int
与class numbers.Integral
有关?
目前没有回答
相关问题 更多 >
编程相关推荐