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

random832 at fastmail.us random832 at fastmail.us
Sun May 31 23:57:30 EDT 2015


On Sun, May 31, 2015, at 10:34, 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 ?

Well, you _can_ create a proper instance if you want.

>>> x = object()
>>> x # incidentally, the repr method is called to produce this output
<object object at 0x1003b8090>
>>> id(x)
4298866832
>>> hash(x)
268679177

The other thing that object does is provide the default implementations
of these methods, so when you inherit from it you don't have to
implement them yourself (equality semantics based on object identity,
str based on repr, repr as shown above)



More information about the Python-list mailing list