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 Sort a Dictionary by Value
Python Keywords and Identifiers
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python bool()
Python Functions
Python List sort()
Python String format()
Python List index()
Python Program to Find ASCII Value of Character
Python List Comprehension
Python Program to Slice Lists
Python memoryview()
Python complex()
Python Program to Transpose a Matrix
Python Program to Display the multiplication Table
Python Program to Print Output Without a Newline
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Program to Iterate Through Two Lists in Parallel
Python strftime()
Python Program to Display Powers of 2 Using Anonymous Function
Python eval()
APIs in Node.js vs Python - A Comparison
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python Program to Iterate Over Dictionaries Using for Loop
Python Global, Local and Nonlocal variables
Python any()
Machine Learning with Python for everyone - Mark E.Fenner
Python Program to Differentiate Between del, remove, and pop on a List
Python bytes()
Python Program to Display Calendar
Python Program to Check If Two Strings are Anagram