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 Occurrence of a Character in String
Python Program to Count the Number of Each Vowel
Python bool()
Python Get Current time
Python Program to Create Pyramid Patterns
Python divmod()
Python Modules
Python if...else Statement
Python len()
Python delattr()
Python Program to Randomly Select an Element From the List
Python String islower()
Python hex()
Python Set intersection_update()
Python Program to Access Index of a List Using for Loop
Python String swapcase()
Python Program to Convert Kilometers to Miles
Python Anonymous / Lambda Function
Python break and continue
Python Function Arguments
Python String lower()
Python String capitalize()
Python Set union()
Python round()
Python map()
Python Package
Python repr()
Python object()
Python help()
Python Program to Append to a File
Python Program to Extract Extension From the File Name
Python Program to Trim Whitespace From a String