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:
True
if class is subclass of a class, or any element of the tupleFalse
otherwise
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 Remove Duplicate Element From a List
Python iter()
Python Program Read a File Line by Line Into a List
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Represent enum
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python String maketrans()
Python id()
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Merge Mails
Python Set intersection_update()
Python Program to Make a Flattened List from Nested List
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Program to Multiply Two Matrices
Python __import__()
Python complex()
Python Program to Append to a File
Python exec()
Python Dictionary fromkeys()
Python dict()
Python Dictionary values()
Python timestamp to datetime and vice-versa
Python bool()
Python Program to Convert Kilometers to Miles
Python Program to Remove Punctuations From a String
Python Program to Concatenate Two Lists
Python String rjust()
Python Program to Find the Sum of Natural Numbers
Python File I/O Operation
Python Package
Python Sets
Python Program to Shuffle Deck of Cards