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 Count the Number of Digits Present In a Number
Python input()
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python Errors and Built-in Exceptions
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python Set difference()
Python Program to Get the Full Path of the Current Working Directory
Python Program to Remove Punctuations From a String
Python slice()
Python List append()
Python Generators
Python Global, Local and Nonlocal variables
Python locals()
Python Program to Find the Factors of a Number
Python Program to Make a Flattened List from Nested List
Python pow()
Intelligent Projects Using Python - Santanu Pattanayak
Python divmod()
Python Function Arguments
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Print Output Without a Newline
Python bin()
Python Program to Get File Creation and Modification Date
Python Program Read a File Line by Line Into a List
Python hex()
Python Exception Handling Using try, except and finally statement
Python Functions
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python type()
Python Program to Make a Simple Calculator
Python String index()
Python String partition()