English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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() has two parameters:
object -The class to be checked
classinfo-Class, type, or class and type of tuple
The return value of issubclass():
True ifobjectis a subclass of the class, or any element of the tuple
False except
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.