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.
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 ?
*** The interpreter creates two classes type and object when setting up a
python environment. right ?
*** The creator (metaclass) of all data types (i.e. int,str) in python is the
class type. right ?
>>> isinstance(int,type)
True
*** The instance of class type is a data type an instance of class type. right ?
>>> type(type)
<class 'type'>
>>> isinstance(type,type)
True
*** Class type gets some of its behavior from class object through
inheritance.right ?
>>> issubclass(type,object)
True
*** instance of class object is type, in the sense it created using class type
which inherits from class object.right ?
>>> isinstance(object,type)
True
>>> isinstance(object,object)
True
****so is it right to say, everything in python is an object because they are
instance of the class type which inherits from class object ?
--
https://mail.python.org/mailman/listinfo/python-list