type vs. class

Carel Fellinger cfelling at iae.nl
Mon Dec 11 07:33:47 EST 2000


Thomas Thiele <tnt-audio at t-online.de> wrote:
> Hallo!

> simple typetest

>>>> type(3)
> <type 'int'>

>>>> class X:
> 	pass
> 	
>>>> x = X()
>>>> type(x)
> <type 'instance'>

> How can I realize that I will not get type 'instance' but type 'X'? I

have a look at the build-in functions isinstance() and issubclass()

> have different classes, more than one, and I want to check out which
> class it is.  Are all classes type instance?

No, classes are of type Class:)  You see, python doesn't do types like
say Pascal. It has two levels of type. The first level deals with integers,
floats, lists, functions, classes, etc. The second level gives a finer
grain of type distinction, but only for classes.  The type function only
deals with the first level of types.  The above mentioned isinstance and
issubclass functions deal with the second, class oriented level of types.

The language itself only uses the first level of types and ignores the
other.  The nice side of this dichotomy is that programs tend to focus
on interface instead of class type.  So as long as an instance provides
all the methods used al is swell.
-- 
groetjes, carel



More information about the Python-list mailing list