Everything is an object in python - object class and type class

Rustom Mody rustompmody at gmail.com
Tue Jun 2 07:40:33 EDT 2015


On Tuesday, June 2, 2015 at 4:57:31 PM UTC+5:30, Steven D'Aprano wrote:
> On Tue, 2 Jun 2015 08:36 pm, Eddilbert Macharia wrote:
> 
> > you guys are just confusing me, you are going in loops, and still i have
> > understood ,what makes everything in python an object. hey is where i'm at
> > : *** type in python refers to data types e.g. int, str, boolean e.t.c.
> > right ?
> 
> Yes. Also classes you create with the "class" keyword:
> 
> class K(object):
>     ...
> 
> K is now a "type", just like int, str, list, object, etc.
> 
> 
> > *** The interpreter creates two classes type and object when setting up a
> > python environment. right ?
> 
> Many more than just two: it also creates list, str, dict, etc. But *first*
> it has to create type and object. So you are correct.
> 
> 
> > *** The creator (metaclass) of all data types (i.e. int,str) in python is
> > the class type. right ?
> 
> Correct.
> 
> [Aside: I'm only talking about Python 3 here. In Python 2 there is also a
> second hierarchy of classes, called "classic classes" or "old-style
> classes", which are *not* subclasses of type. But let's just ignore them,
> because they are gone in the most recent versions of Python.]
> 
> 
> >>>> isinstance(int,type)
> > True
> > 
> > *** The instance of class type is a data type an instance of class type.
> > right ?
> >>>> type(type)
> > <class 'type'>
> 
> type has many instances, not just one.

Not sure what you are trying to emphasize by the 'not just one'
In particular the issubclass relation is transitive
Whereas the isinstance is not

>>> isinstance(2,int)
True
>>> isinstance(int,type)
True
>>> isinstance(2,type)
False



More information about the Python-list mailing list