Python issubclass() built-in function
From the Python 3 documentation
Return True if class is a subclass (direct, indirect, or virtual) of classinfo. A class is considered a subclass of itself. classinfo may be a tuple of class objects (or recursively, other such tuples) or a Union Type, in which case return True if class is a subclass of any entry in classinfo. In any other case, a TypeError exception is raised.
Introduction
The issubclass()
function in Python is a built-in function that checks if a given class is a subclass of another class or a tuple of classes. It returns True
if the first argument is a subclass of the second argument, and False
otherwise. This function is useful for object-oriented programming, as it allows you to verify class relationships and implement polymorphic behavior based on inheritance.
Examples
class First:
pass
class Second(First):
pass
print(issubclass(Second, First)) # True
print(issubclass(First, Second)) # False