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 isalnum()
Python String title()
Python Program to Convert Bytes to a String
Python type()
Python Program to Find Hash of File
Python round()
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Program to Get the File Name From the File Path
Python Object Oriented Programming
Python Directory and Files Management
Python Set symmetric_difference()
Python Set difference_update()
Python timestamp to datetime and vice-versa
Python String isdigit()
Python RegEx
Python Program to Print the Fibonacci sequence
Python memoryview()
Python Set add()
Python Program to Convert Kilometers to Miles
Python Program to Solve Quadratic Equation
Python str()
Python String index()
Python Tuple index()
Python Program to Check Prime Number
Python Program to Check Armstrong Number
Python String rjust()
Python id()
Python Program to Create Pyramid Patterns
Python Program to Display Fibonacci Sequence Using Recursion
Python Dictionary get()
Python Program to Differentiate Between type() and isinstance()
Python isinstance()