What is the Python base class?

Viewed 86

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?

1 Answers

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'>)
Related