Difference between type and class

Nikolaus Rath Nikolaus at rath.org
Thu Jul 31 17:25:25 CEST 2008

Maric Michaud <maric at aristote.info> writes:
> Le Thursday 31 July 2008 16:46:28 Nikolaus Rath, vous avez écrit :
>> Maric Michaud <maric at aristote.info> writes:
>> >> > Can someone explain to me the difference between a type and a class?
>> >>
>> >> If your confusion is of a more general nature I suggest reading the
>> >> introduction of `Design Patterns' (ISBN-10: 0201633612), under
>> >> `Specifying Object Interfaces'.
>> >>
>> >> In short: A type denotes a certain interface, i.e. a set of signatures,
>> >> whereas a class tells us how an object is implemented (like a
>> >> blueprint). A class can have many types if it implements all their
>> >> interfaces, and different classes can have the same type if they share a
>> >> common interface. The following example should clarify matters:
>> >
>> > Of course, this is what a type means in certain literature about OO
>> > (java-ish), but this absolutely not what type means in Python. Types
>> > are a family of object with a certain status, and they're type is
>> > "type", conventionnaly named a metatype in standard OO.
>> [...]
>> Hmm. Now you have said a lot about Python objects and their type, but
>> you still haven't said what a type actually is (in Python) and in what
>> way it is different from a class. Or did I miss something?
> This paragraph ?
> """
> - types, or classes, are all instance of type 'type' (or a subclass of it), 

Well, I couldn't quite make sense of '..are instance of type...'
without knowing what you actually meant with "type* in this context,

> Maybe it's still unclear that "types" and "classes" *are* synonyms
> in Python.

..in this case it becomes clear. Then my question reduces to the one
in the other post (why do 'int' and 'myint' have different __repr__

Already thanks for your help,


 »It is not worth an intelligent man's time to be in the majority.
  By definition, there are already enough people to do that.«
                                                         -J.H. Hardy

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C

More information about the Python-list mailing list