English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python Basic Tutorial

Python Flow Control

Fonctions en Python

Types de données en Python

Python File Operations

Python Objects and Classes

Python Date and Time

Advanced Python Knowledge

Python Reference Manual

Usage and examples of Python issubclass()

Python built-in functions

The issubclass() function checks whether the parameter (the first parameter object) is a subclass of the classinfo class (the second parameter).

The syntax of issubclass():

issubclass(object, classinfo)

issubclass() parameters

issubclass() has two parameters:

  • object -The class to be checked

  • classinfo-Class, type, or class and type of tuple

The return value of issubclass():

The return value of issubclass():

  • True ifobjectis a subclass of the class, or any element of the tuple

  • False except

Example: How does issubclass() work?

class Polygon:
  def __init__(polygonType):
    print('The polygon is ', 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)))

When running the program, the output is:

True
False
True
True

It is important to note that classes are considered to be their own subclasses.

Python built-in functions