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 Dictionary copy()
Python globals()
Python classmethod()
Python hex()
Python repr()
Python Closures
Python Program to Print all Prime Numbers in an Interval
Python pow()
Python @property decorator
Python Program to Delete an Element From a Dictionary
Python iter()
Python String istitle()
Python bool()
Deep Learning in Python - LazyProgrammer
Python bytearray()
Python Set intersection()
Python Namespace and Scope
Python List index()
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python Program to Slice Lists
Python Program to Get File Creation and Modification Date
Python all()
Python Global Keyword
Python Program to Get the Full Path of the Current Working Directory
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python Program to Safely Create a Nested Directory
Python Program to Copy a File
Python List clear()
Python str()
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python String isalpha()
Python Program to Print Hello world!