Difference between type and class
semanticist at gmail.com
Fri Aug 1 00:58:24 CEST 2008
On Thu, Jul 31, 2008 at 1:59 PM, Nikolaus Rath wrote:
> If it is just a matter of different rendering, what's the reason for
> doing it like that? Wouldn't it be more consistent and straightforward
> to denote builtin types as classes as well?
Yes, and in Python 3, it will be so:
>>> class myint(int): pass
The reason the distinction is made currently is that before Python
2.2, "types" were built-in (or C extension) classes, and "classes"
were Python classes; it was not possible to subclass built-in types.
That "classic" style of classes are still supported in Python 2.2 and
above (but not in Python 3), by not inheriting from object or any
other built-in. However, for new-style classes, the only distinction
is in the repr.
>>> class classic: pass
>>> class newstyle(object): pass
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: class classic has no attribute '__class__'
<class __main__.classic at 0x64e70>
More information about the Python-list