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 Dictionary keys()
Python Program to Display the multiplication Table
Python String splitlines()
Python String isupper()
Python strptime()
Python while Loop
Python round()
Python String isidentifier()
Machine Learning with Python for everyone - Mark E.Fenner
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python Program to Sort Words in Alphabetic Order
Python timestamp to datetime and vice-versa
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python Program to Print Hello world!
Python divmod()
Python Program to Slice Lists
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Deep Learning Cookbook - Indra den Bakker
Python Exception Handling Using try, except and finally statement
Python int()
Python tuple()
Python Program to Find Sum of Natural Numbers Using Recursion
Python Objects and Classes
Python Dictionary items()
Python Set issuperset()
Deep Learning with Python - Francois Chollet
Python Program to Convert Celsius To Fahrenheit
Python Variables, Constants and Literals
Python String isalpha()
Introduction to Scientific Programming with Python - Joakim Sundnes
Python __import__()
Python Directory and Files Management