Re: Difference between type and class



oj <ojeeves@xxxxxxxxx> writes:
On Jul 31, 11:37 am, Nikolaus Rath <Nikol...@xxxxxxxx> 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
.



Relevant Pages

  • Re: Difference between type and class
    ... Why can't I say that 'int' is a class and 'myclass' ... But there seems to be a distinction: ... What the <type int> means is that int is not a user type but a builtin type, ...
    (comp.lang.python)
  • Re: Difference between type and class
    ... Why can't I say that 'int' is a class and 'myclass' ... A class (lets call it SomeClass for this example) is an ... If there is no distinction, how does the Python interpreter know when ...
    (comp.lang.python)
  • Re: This I simply cant swallow
    ... encapsulation and abstract data types are completely orthogonal ... int i; ... MyClass i; //An instance of MyClass ... An ADT is a type that cannot, itself, be instantiated. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: tutorials
    ... I have a Fortran reference from about 1977 where the disctinction ... most important to make a clear distinction. ... int main ... call to foo and the and the x declared in foo? ...
    (comp.lang.c)
  • Re: What is a type?
    ... > In your example of the difference between int and const int, ... The program types are clearly different, ... yet the representation types are exactly the same. ... So I see the "program type/representation type" distinction ...
    (comp.lang.c)