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:
Trueif class is subclass of a class, or any element of the tupleFalseotherwise
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 ascii()
Python oct()
Python String rjust()
Python Program to Return Multiple Values From a Function
Introduction to Scientific Programming with Python - Joakim Sundnes
Python Program to Create a Long Multiline String
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python List index()
Python Program to Catch Multiple Exceptions in One Line
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Program to Swap Two Variables
Python Program to Calculate the Area of a Triangle
Python Program to Remove Punctuations From a String
Python String ljust()
Python datetime
Python next()
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python Set intersection_update()
Python Dictionary copy()
Python tuple()
Python bytes()
Python getattr()
Python Program to Find Factorial of Number Using Recursion
Python Set union()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python dict()
Python Set difference()
Python Set add()
Python Program to Find HCF or GCD
Python Variables, Constants and Literals
Python String isdigit()