isinstance() and issubclass()

The isinstance() method is used to determine if an object belongs to a specific class, while the issubclass() method checks if one class is derived from another class or classes, establishing a subclass relationship.

isinstance(object, classinfo)

The isinstance() function returns True if the provided object is an instance of the class specified in the classinfo argument, or of any subclass (direct, indirect, or virtual) derived from it.

issubclass(class, classinfo)

The issubclass() function returns True if the given class is a subclass (direct, indirect, or virtual) of the class specified in the classinfo argument. It also considers a class to be a subclass of itself.

example
class MyClass(object): pass class MySubClass(MyClass): pass print(isinstance(MySubClass, object)) print(issubclass(MySubClass, MyClass)) print(isinstance(MySubClass, MyClass))
output
True True False