Difference between type and class

Nikolaus Rath Nikolaus at rath.org
Thu Jul 31 14:30:19 CEST 2008


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'>

why doesn't this print

>>> class int_class(object):
...   pass
... 
>>> int_class
<type '__main__.int_class'>
>>> int
<type 'int'>

or

>>> class int_class(object):
...   pass
... 
>>> int_class
<class '__main__.int_class'>
>>> int
<class 'int'>

If there is no distinction, how does the Python interpreter know when
to print 'class' and when to print 'type'?


Best,

   -Nikolaus

-- 
 »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