# python2
Python 2.7.5 (default, Dec 8 2017, 16:39:59)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-25)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class C: pass
...
>>> class N(object): pass
...
>>> I1 = C()
>>> I2 = N()
>>>
>>> type(I1)
<type 'instance'>
>>> I1.__class__
<class __main__.C at 0x7f5b1d8fb870>
>>> type(C)
<type 'classobj'>
>>> type(I2)
<class '__main__.N'>
>>> I2.__class__
<class '__main__.N'>
>>> type(N)
<type 'type'>
>>>
>>> isinstance(I1, object)
True
>>> isinstance(I2, object)
True
>>>
For classic classes, type(obj)
output differently from obj.class
because that type
and class
are not the same thing.
For new-style classes, type
and class
are merged, type
is class
while class
is type
.
isinstance(I2, object)
returns true
because new-style class N is a subclass of object
.
isinstaece(I1, object)
returns true
because everything in python is an instance of object
, including object
itself.