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 String isidentifier()
Python filter()
Python dict()
Deep Learning with Python - Francois Cholletf
Python Multiple Inheritance
Python Inheritance
Python Program to Get the Class Name of an Instance
Python Tuple
Python Program to Print Hello world!
Python @property decorator
Python List pop()
Python Program to Find the Largest Among Three Numbers
Python pass statement
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Program to Get a Substring of a String
Python Set discard()
Python strftime()
Python open()
Python Dictionary fromkeys()
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Compute the Power of a Number
Python Program to Find Armstrong Number in an Interval
Python Statement, Indentation and Comments
Python Program Read a File Line by Line Into a List
Python String center()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Intelligent Projects Using Python - Santanu Pattanayak
Python all()
Python Program to Find the Size (Resolution) of a Image
Python setattr()
Python pow()
Python input()