Difference between type and class

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Aug 5 08:40:58 CEST 2008


En Thu, 31 Jul 2008 09:30:19 -0300, Nikolaus Rath <Nikolaus at rath.org>  
escribi�:

> oj <ojeeves at gmail.com> writes:
>> On Jul 31, 11:37 am, Nikolaus Rath <Nikol... at rath.org> wrote:
>>> So why does Python distinguish between e.g. the type 'int' and the
>>> class 'myclass'? Why can't I say that 'int' is a class and 'myclass'
>>> is a type?
>>
>> I might be wrong here, but I think the point is that there is no
>> distinction. A class (lets call it SomeClass for this example) is an
>> object of type 'type', and an instance of a class is an object of type
>> 'SomeClass'.
>
> But there seems to be a distinction:
>
>>>> class int_class(object):
> ...   pass
> ...
>>>> int_class
> <class '__main__.int_class'>
>>>> int
> <type 'int'>
> [...]
> If there is no distinction, how does the Python interpreter know when
> to print 'class' and when to print 'type'?

If it helps you to understand the issue, in Python 3.0 that difference is  
gone - the word "class" is used on both cases. See  
http://bugs.python.org/issue2565

-- 
Gabriel Genellina




More information about the Python-list mailing list