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 divmod()
Python Program to Count the Number of Digits Present In a Number
Python Package
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Program Read a File Line by Line Into a List
Python Program to Find ASCII Value of Character
Python Program to Create a Long Multiline String
Deep Learning with Python - Francois Cholletf
Python float()
Python frozenset()
Python Operator Overloading
Python Program to Shuffle Deck of Cards
Python Program to Find Armstrong Number in an Interval
Python Program to Check if a Key is Already Present in a Dictionary
Python String expandtabs()
Python Objects and Classes
Python String swapcase()
Python object()
Python Program to Get the Full Path of the Current Working Directory
Python Program to Convert String to Datetime
Python Program to Find the Sum of Natural Numbers
Python Generators
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Convert Bytes to a String
Python Program to Check Armstrong Number
Python Program to Access Index of a List Using for Loop
Python sorted()
Python String rjust()
Python reversed()
Python Program to Get the Class Name of an Instance
Python Set issubset()
Python getattr()