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 Tuple count()
Python frozenset()
Python Program to Check if a Number is Odd or Even
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python zip()
Python List reverse()
Python Variables, Constants and Literals
Python frozenset()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python chr()
Python for Loop
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python String title()
Python Program to Find Factorial of Number Using Recursion
Python Program to Get a Substring of a String
Python String format()
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python Program to Extract Extension From the File Name
Python Program to Make a Flattened List from Nested List
Python List pop()
Python Dictionary keys()
Python Namespace and Scope
Python Deep Learning Cookbook - Indra den Bakker
Python String index()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Anonymous / Lambda Function
Python String ljust()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python RegEx
Python Set symmetric_difference()
Python String partition()
Python Data Structures and Algorithms - Benjamin Baka