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

Eddilbert Macharia edd.cowan at gmail.com
Sun May 31 20:29:52 EDT 2015


So what im getting from above reponse, everything in python is an object because the are instance of the metaclass type and also because they are subclasses of the class object ?


On Sunday, May 31, 2015 at 5:34:20 PM UTC+3, Eddilbert Macharia wrote:
> Hello All ,
> 
> I'm wrecking my head trying to understand. where the class object comes into play . 
> 
> Is it only meant to act as base class and does it mean there is an actual class called object in python which all the objects created using the class type inherit ?
> 
> i'm assuming the metaclass if simplified would look something like this :
> 
> type('dict', (object,),{})
> 
> And when we use the class type as a metaclass are we using the instance version of the class type or are we actually using the type class itself ?
> 
> Also when we say everything is an object in python, are we referring to the fact that everything is an instance of the class type or does it have to with the object class inherited ? 
> 
> As can be attested by using type() function as below :
> 
> >>> type(int)
> <class 'type'>
> >>> type(list)
> <class 'type'>
> >>> type(dict)
> <class 'type'>
> >>> type(type)
> <class 'type'>
> >>> type(object)
> <class 'type'>
> 
> From my understanding this means all of this are instances of the class type. which means the class type was used to create this instances.
> 
> Now if i look at the __bases__ of all this objects i get :
> 
> >>> type.__base__
> <class 'object'>
> >>> type.__bases__
> (<class 'object'>,)
> >>> dict.__bases__
> (<class 'object'>,)
> >>> list.__bases__
> (<class 'object'>,)
> >>> int.__bases__
> (<class 'object'>,)
> >>> object.__bases__
> ()
> 
> This tells me that all of this objects inherit from the class object which has nothing to do with them being instances.



More information about the Python-list mailing list