In this tutorial, we will learn about the python issubclass() method and its use with examples.

Python issubclass() Method

What is the Python issubclass() Method?

The python issubclass() method returns True if the specified object is an instance or subclass; otherwise, it will return False.

The syntax of issubclass() is:

issubclass(object, class)

Python issubclass() Method Parameters

issubclass() method takes two parameters as arguments:

  • object – Name of the object to be checked
  • class – Type of the class.

Let’s see some examples of the python issubclass() method.

Example 1: How to Use issubclass() python method?

class Polygon:
  def __init__(polygonType):
    print('Polygon is a ', polygonType)

class Triangle(Polygon):
  def __init__(self):

    Polygon.__init__('triangle')
   
print(issubclass(Triangle, Polygon))
print(issubclass(Triangle, list))
print(issubclass(Triangle, (list, Polygon)))
print(issubclass(Polygon, (list, Polygon)))

The output will be as follow:

True
False
True
True

 

Was this article helpful?
Share on: