Table of Contents
The issubclass() function checks if the class argument (first argument) is a subclass of classinfo class (second argument).
The syntax of issubclass() is:
issubclass(class, classinfo)
1. issubclass() Parameters
issubclass() takes two parameters:
- class – class to be checked
- classinfo – class, type, or tuple of classes and types
2. Return Value from issubclass()
issubclass() returns:
Trueif class is subclass of a class, or any element of the tupleFalseotherwise
3. 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.
Related posts:
Python len()
Python tuple()
Python dict()
Python *args and **kwargs
Python next()
Python Program to Iterate Over Dictionaries Using for Loop
Python Package
Python iter()
Python Program to Calculate the Area of a Triangle
Python time Module
Python enumerate()
Python hash()
Python String count()
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Program to Illustrate Different Set Operations
Python Program to Find All File with .txt Extension Present Inside a Directory
Python String istitle()
Python Program to Print Colored Text to the Terminal
Python List index()
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python divmod()
Python Dictionary pop()
Python String islower()
Python List insert()
Python Program to Print Hello world!
Machine Learning with Python for everyone - Mark E.Fenner
Python Program to Display Powers of 2 Using Anonymous Function
Python for Loop
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Set intersection()
Python Functions
Python Program to Compute the Power of a Number