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 Safely Create a Nested Directory
Python Tuple index()
Python Dictionary values()
Python datetime
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Merge Two Dictionaries
APIs in Node.js vs Python - A Comparison
Python hex()
Python Dictionary fromkeys()
Python Set symmetric_difference_update()
Python String rindex()
Python print()
Python String islower()
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python List copy()
Python String casefold()
Python Program to Get File Creation and Modification Date
Python Program to Iterate Over Dictionaries Using for Loop
Python File I/O Operation
Python Dictionary copy()
Python Program to Count the Number of Digits Present In a Number
Python Program to Iterate Through Two Lists in Parallel
Python Program to Convert String to Datetime
Python Program to Count the Occurrence of an Item in a List
Python Program to Check Whether a String is Palindrome or Not
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python String isupper()
Python Program to Find the Factors of a Number
Python Shallow Copy and Deep Copy
Python String title()
Python oct()
Python Function Arguments