Is type object an instance or class?

JH john.hsu at sovereign.co.nz
Mon Feb 26 21:00:00 EST 2007


Hi

I found that a type/class are both a subclass and a instance of base
type "object".

It conflicts to my understanding that:

1.) a type/class object is created from class statement
2.) a instance is created by "calling" a class object.

A object should not be both a class and an instance at the same time.

Further I found out there is a special type call "type" that is a
subclass of base type "object". All other types are instances of this
type.  Even base type "object" is an instance of this special type.

What is role of this type "type" in object creation?  Could someone
there straighten this concept a little?

For example (Python2.5):

>>> issubclass(int, object)
True
>>> isinstance(int, object)
True
>>> print type(int)
<type 'type'>
>>> isinstance(int, type)
True
>>> issubclass(int, type)
False
>>> issubclass(type, object)
True
>>> isinstance(type, object)
True
>>> isinstance(object, type)
True
>>>




More information about the Python-list mailing list