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 locals()
Python List insert()
Python Program to Access Index of a List Using for Loop
Python Set add()
Python String isnumeric()
Python Operator Overloading
Python Anonymous / Lambda Function
Python Keywords and Identifiers
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Dictionary setdefault()
Python Program to Shuffle Deck of Cards
Python Program to Find the Size (Resolution) of a Image
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python *args and **kwargs
Python Input, Output and Import
Python String rpartition()
Python Program to Check if a Number is Odd or Even
Python memoryview()
Python Program to Find Sum of Natural Numbers Using Recursion
Python round()
Python String encode()
Python String center()
Python String join()
Python Dictionary items()
Python Program to Find the Square Root
Python Dictionary clear()
Python hex()
Python reversed()
Python List extend()
Python List copy()
Python next()
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj