class Classname(object), what sort of word is 'object' in Python? class Classname(object), what sort of word is 'object' in Python? python python

class Classname(object), what sort of word is 'object' in Python?


object is a (global) variable. By default it is bound to a built-in class which is the root of the type hierarchy.

(This leads to the interesting property that you can take any built-in type, and use the __bases__ property to reach the type called object).

Everything built-in that isn't a keyword or operator is an identifier.


The following three class declarations are identical in Python 3

class Classname(object):    passclass Classname():    passclass Classname:    pass

Well, there will be minor differences, but not fundamentally important since the object class is the base for all.

If you plan to write Python agnostic code (Python2 and Python3 agnostic) you may use the first declaration.


object is an identifier that refers to a builtin type.

Unlike many other languages, there are no primitive types in Python. Everything is an object, including all data types.

I'm not sure why you expected inheriting from randomobject to work.