Python issubclass()

The syntax of issubclass() is:

issubclass(class, classinfo)

issubclass() Parameters

issubclass() takes two parameters:

  • class - class to be checked
  • classinfo - class, type, or tuple of classes and types

Return Value from issubclass()

issubclass() returns:

  • True if class is subclass of a class, or any element of the tuple
  • False otherwise

Example: How issubclass() works?

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)))

Output

True
False
True
True

It's important to note that class is considered a subclass of itself.


Also Read:

Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges