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 keys()
Python Dictionary values()
Python Type Conversion and Type Casting
Python String casefold()
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python Recursion
Python Directory and Files Management
Python Program to Compute the Power of a Number
Python List clear()
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python String rpartition()
Python Dictionary fromkeys()
Node.js vs Python for Backend Development
Python Program to Append to a File
Python Program to Get Line Count of a File
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Convert Celsius To Fahrenheit
Python Program to Find Factorial of Number Using Recursion
Python String isupper()
Python for Loop
Python frozenset()
Python Tuple
Python Program to Display Powers of 2 Using Anonymous Function
Python Program to Check if a Key is Already Present in a Dictionary
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Program to Find ASCII Value of Character
Python String find()
Python hex()
Python String swapcase()
Python Program to Iterate Over Dictionaries Using for Loop
Python Program Read a File Line by Line Into a List
Python int()