class vs type

Hrvoje Niksic hniksic at xemacs.org
Fri Oct 19 15:12:14 CEST 2007


"Colin J. Williams" <cjw at sympatico.ca> writes:

> In Python Types and Objects, Shalabh Chaturvedi says (in the Python
> 3.0 documentation - New Style Classes)
>
> "The term class is traditionally used to imply an object created by
> the class statement. However, classes are now synonymous with
> types. Built-in types are usually not referred to as classes. This
> book prefers using the term type for both built-in and user created
> types."
>
> Do we need two different words to describe what is essentially the
> same thing?

We don't, not anymore, which is why the author chooses the word "type"
for both in the last sentence.

But, as the author correctly explains, class and type used to not be
the same thing.  Classes were created with 'class', and they were
fundamentally different from C types created in extension modules.
All instances of old-style classes are of type 'instance', which is
why they have the __class__ attribute, so you can find their actual
class.  (Functions like "isinstance" contain hacks to support
old-style classes.)  New-style classes elevate Python-level classes to
types equal to the built-in ones, which is why the word "type" is now
sufficient for both.



More information about the Python-list mailing list