issubclass(class, classinfo)
The issubclass function takes two classes, class and classinfo, as arguments, and returns the boolean True if class is a subclass of classinfo, or False otherwise.
A class is always considered a subclass of itself.
- class: Class to evaluate.
- classinfo: Class of which we want to know whether or not class is a subclass.
The issubclass function returns a boolean.
To test this function we are going to create a class and a subclass of it:
class circle:
def __init__(self, radio):
self.radio = radio
class colored_circle(circle):
def __init__(self, radio, color):
super().__init__(radio)
self.color = color
We can now confirm if the colored_circle class is a subclass of circle with the following code:
issubclass(colored_circle, circle)
True
However:
issubclass(colored_circle, int)
False
... as colored_circle is not, of course, a subclass of integers.
A class is always considered a subclass of itself:
issubclass(circle, circle)
True