2

What is the base class in python or base Object? For example we have base exception for the exceptions, but do we have a base class for the classes or objects?

  • Does this answer your question? [What are metaclasses in Python?](https://stackoverflow.com/questions/100003/what-are-metaclasses-in-python) – Hollay-Horváth Zsombor Apr 01 '20 at 13:12
  • What do you mean by *the* base class? Classes can have arbitrary base classes. ``object`` is the common ancestor of all builtin classes *by convention* and all custom classes *by consequence* (as they must inherit from a builtin class) but one could in principle create a new builtin class that does not (pretend to) derive from ``object``. – MisterMiyagi Apr 01 '20 at 13:26
  • I meant the masterclass of all classes. How would you create a class that is not derived from object? Built-in and custom? – Claud Bejan Apr 01 '20 at 13:48

1 Answers1

3

It's the object class.

You can check this by using inspect.getmro which returns the entire class hierarchy of a type.

example:

import inspect

class A: # inherits nothing
  pass

class B(A): # inherits A
  pass

print(inspect.getmro(B))
print(inspect.getmro(A))

Output:

(<class '__main__.B'>, <class '__main__.A'>, <class 'object'>)
(<class '__main__.A'>, <class 'object'>)
Adam.Er8
  • 12,675
  • 3
  • 26
  • 38