Is type object an instance or class?

James Stroud jstroud at mbi.ucla.edu
Mon Feb 26 23:00:53 EST 2007


JH wrote:
> 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
> 
> 

Here is a primer on the topic:

http://www.python.org/download/releases/2.2/descrintro/

James



More information about the Python-list mailing list