In Python 2.x, all new-style classes inherit from objectimplicitly or explicitly. Then look at this:
>>> class M(type):
... pass
...
>>> class A:
... __metaclass__ = M
...
>>> class B:
... pass
...
>>> a = A()
>>> b = B()
>>> type(A)
<class '__main__.M'>
>>> type(a)
<class '__main__.A'>
Does this mean what Ais the class of the new style? But Adoes not inherit from object, anyway?
>>> type(B)
<class 'classobj'>
>>> type(b)
<type 'instance'>
OK, Ba classic class, right?
>>> isinstance(A, object)
True
>>> isinstance(B, object)
True
why instances Aand Binstances object?
If it Bis an instance object, then type(B)it won’t classobj, right?
source
share