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 Program to Represent enum
Python Global, Local and Nonlocal variables
Python Program to Check Armstrong Number
Python Program to Display the multiplication Table
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Dictionary keys()
Python String isdigit()
Python Dictionary pop()
Python String capitalize()
Python int()
Python iter()
Python Closures
Python String lower()
Python Set union()
Python String isnumeric()
Python Program to Solve Quadratic Equation
Python String rindex()
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python abs()
Python Errors and Built-in Exceptions
Python String maketrans()
Python Program to Add Two Numbers
Python chr()
Python List count()
Python strptime()
Python list()
Python locals()
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Check If Two Strings are Anagram
Python Set intersection_update()
Python vars()
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli