Python issubclass function in details

issubclass() function in python :

In python, issubclass() function is used to check if a class is a subclass of another class. The syntax of the function is :

python issubclass

It will return one boolean value. True if class B is a subclass or derived class of class A, False otherwise. We can also send one tuple as the second argument to this function like below :

python issubclass

It will check if B is a subclass of A or B is a subclass of C etc.
In this tutorial, we will show you how to use issubclass() function with example.

Check if one class is a subclass of another class :

Let’s try issubclass with one single class. Both of the parameters are one single class. We will create three different classes and test if one class is a subclass of another class :

You can download the code from here.

python issubclass

It will print the below output :

python issubclass

python issubclass

Using issubclass to check one class is the subclass of another tuple of classes :

We can also use issubclass to check one class with another tuple of classes. Like below :

python issubclass

It will print the below output :

python issubclass

python issubclass
The output is True because ChildClass is a subclass of MainClass. Note that ChildClass is not a subclass of GrandChildClass.
You might also like :

Leave a Reply