Re: Difference between type and class



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

So int is a type, but if you have an int variable, its type is int.

Same for your classes.

This is, ignoring old style classes. Make sure all your classes
inherit from object to get new style classes.
.



Relevant Pages

  • 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: Is Class Synonymous with Type?
    ... which inherit System.ValueType, which inherits System.Object. ... The above declare three variables in C of type int, float and pointer to ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Why this fix work ?
    ... "int" is 32 bits wide. ... This is basically a matter of luck -- bad luck that it works at ... MyClass* myobj; ... "MyClass *", which is actually 64 bits wide. ...
    (comp.lang.c)
  • Re: Class Destroys itself straight away!
    ... CRectangle; ... int area ... MyClass mc = MyClass; ... void MyClass::SayHello ...
    (microsoft.public.vc.language)
  • Re: Explicit function vs. overloaded operator?
    ... > void operator() (int x, ... The conceptual advantage is that if class MyClass does just one thing, ... make the code easier to read. ...
    (comp.lang.cpp)