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:
Intelligent Projects Using Python - Santanu Pattanayak
Python Sets
Python Program to Calculate the Area of a Triangle
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python super()
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Program to Check if a Number is Odd or Even
Python type()
Python Program to Find Factorial of Number Using Recursion
Python Deep Learning Cookbook - Indra den Bakker
Python pass statement
Python abs()
Deep Learning in Python - LazyProgrammer
Python Dictionary clear()
Python Inheritance
Python hasattr()
Python Program to Transpose a Matrix
Python Program to Shuffle Deck of Cards
Python Anonymous / Lambda Function
Python min()
Python Dictionary copy()
Python hash()
Python id()
APIs in Node.js vs Python - A Comparison
Python __import__()
Python open()
Python Keywords and Identifiers
Python String ljust()
Python next()
Python break and continue
Python String endswith()
Python Program to Check if a Key is Already Present in a Dictionary