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 String splitlines()
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python Set symmetric_difference_update()
Python Matrices and NumPy Arrays
Python Errors and Built-in Exceptions
Python Tuple
Python setattr()
Python Closures
Python Program to Merge Mails
Python object()
Python Program to Illustrate Different Set Operations
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Program to Find the Sum of Natural Numbers
Python Program to Catch Multiple Exceptions in One Line
Python Program to Trim Whitespace From a String
Python Program to Solve Quadratic Equation
Python Program to Find the Square Root
Python Set clear()
Python Set copy()
Python Program to Convert Bytes to a String
Python tuple()
Python String expandtabs()
Python Program to Transpose a Matrix
Python Dictionary pop()
Python List copy()
Python Package
Python classmethod()
Python Program to Convert Decimal to Binary Using Recursion
Python Set intersection()
Python Program to Calculate the Area of a Triangle
Python String partition()
Python Program to Get Line Count of a File