issubclass

Full name
issubclass
Library
Built-in
Syntax

issubclass(class, classinfo)

Description

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.

Parameters
  • class: Class to evaluate.
  • classinfo: Class of which we want to know whether or not class is a subclass.
Result

The issubclass function returns a boolean.

Examples

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

Submitted by admin on Wed, 01/13/2021 - 17:40