【发布时间】:2014-05-11 02:33:03
【问题描述】:
在 Python 2 中,类应明确定义为对象的子类。在 Python 3 中,这将是 默认。
>>> class A(object):
pass
>>> class B():
pass
>>> type(B)
<type 'classobj'>
>>> type(A)
<type 'type'>
我使用 Python 2.7,据我所知,在 2.7 中 class 继承自 object。
【问题讨论】:
-
阅读本文以了解新样式类 stackoverflow.com/questions/4015417/…?
-
我很确定
class在 python >=3.0 中继承自object,但不是 2.7。在 python 2.x 中,您仍然必须从object显式继承。
标签: python class inheritance