What is the difference between 'type' and 'class'?

Duncan Booth duncan.booth at invalid.invalid
Tue Jun 22 08:03:13 EDT 2010


Peng Yu <pengyu.ut at gmail.com> wrote:

> pydoc xrange says:
> 
> Help on class xrange in module __builtin__:
> 
> class xrange(object)
> 
> python_2.6.5_library.pdf says:
> 
> Objects of type xrange are similar to buffers
> 
> Are type and class synonyms? It seems that they are at least according
> to some webpages that I read. But I'm not completely sure. Could you
> let me know in case my impress is wrong?
> 

In Python every object has a type. The type of an instance is its class. 
The type of a class (also known as its metaclass) is either `type` or a 
subclass of `type` (ignoring old style classes here).

Also for completeness: the type of `type` is `type`. Every object in Python 
is an instance of `object`; the type of `object` is `type` and both `type` 
and `object` are instances of `object` (warning, may cause headaches).

-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list